2017-11-07 01:11:51 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-08-27 02:04:50 +08:00
|
|
|
/*
|
|
|
|
* Synopsys DesignWare 8250 driver.
|
|
|
|
*
|
|
|
|
* Copyright 2011 Picochip, Jamie Iles.
|
2013-01-10 17:25:10 +08:00
|
|
|
* Copyright 2013 Intel Corporation
|
2011-08-27 02:04:50 +08:00
|
|
|
*
|
|
|
|
* The Synopsys DesignWare 8250 has an extra feature whereby it detects if the
|
|
|
|
* LCR is written whilst busy. If it is, then a busy detect interrupt is
|
|
|
|
* raised, the LCR needs to be rewritten and the uart status register read.
|
|
|
|
*/
|
2018-02-09 05:59:56 +08:00
|
|
|
#include <linux/delay.h>
|
2011-08-27 02:04:50 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/serial_8250.h>
|
|
|
|
#include <linux/serial_reg.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/slab.h>
|
2013-01-10 17:25:10 +08:00
|
|
|
#include <linux/acpi.h>
|
2013-03-29 07:15:49 +08:00
|
|
|
#include <linux/clk.h>
|
2014-07-23 23:33:06 +08:00
|
|
|
#include <linux/reset.h>
|
2013-04-10 21:58:28 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2011-08-27 02:04:50 +08:00
|
|
|
|
2013-06-20 04:37:27 +08:00
|
|
|
#include <asm/byteorder.h>
|
|
|
|
|
2013-01-10 17:25:12 +08:00
|
|
|
#include "8250.h"
|
|
|
|
|
2013-01-10 17:25:09 +08:00
|
|
|
/* Offsets for the DesignWare specific registers */
|
|
|
|
#define DW_UART_USR 0x1f /* UART Status Register */
|
|
|
|
#define DW_UART_CPR 0xf4 /* Component Parameter Register */
|
|
|
|
#define DW_UART_UCV 0xf8 /* UART Component Version */
|
|
|
|
|
|
|
|
/* Component Parameter Register bits */
|
|
|
|
#define DW_UART_CPR_ABP_DATA_WIDTH (3 << 0)
|
|
|
|
#define DW_UART_CPR_AFCE_MODE (1 << 4)
|
|
|
|
#define DW_UART_CPR_THRE_MODE (1 << 5)
|
|
|
|
#define DW_UART_CPR_SIR_MODE (1 << 6)
|
|
|
|
#define DW_UART_CPR_SIR_LP_MODE (1 << 7)
|
|
|
|
#define DW_UART_CPR_ADDITIONAL_FEATURES (1 << 8)
|
|
|
|
#define DW_UART_CPR_FIFO_ACCESS (1 << 9)
|
|
|
|
#define DW_UART_CPR_FIFO_STAT (1 << 10)
|
|
|
|
#define DW_UART_CPR_SHADOW (1 << 11)
|
|
|
|
#define DW_UART_CPR_ENCODED_PARMS (1 << 12)
|
|
|
|
#define DW_UART_CPR_DMA_EXTRA (1 << 13)
|
|
|
|
#define DW_UART_CPR_FIFO_MODE (0xff << 16)
|
|
|
|
/* Helper for fifo size calculation */
|
|
|
|
#define DW_UART_CPR_FIFO_SIZE(a) (((a >> 16) & 0xff) * 16)
|
|
|
|
|
2016-11-11 02:07:56 +08:00
|
|
|
/* DesignWare specific register fields */
|
|
|
|
#define DW_UART_MCR_SIRE BIT(6)
|
2013-01-10 17:25:09 +08:00
|
|
|
|
2011-08-27 02:04:50 +08:00
|
|
|
struct dw8250_data {
|
2013-09-05 22:34:53 +08:00
|
|
|
u8 usr_reg;
|
|
|
|
int line;
|
2015-02-27 08:35:57 +08:00
|
|
|
int msr_mask_on;
|
|
|
|
int msr_mask_off;
|
2013-09-05 22:34:53 +08:00
|
|
|
struct clk *clk;
|
2014-06-16 21:25:17 +08:00
|
|
|
struct clk *pclk;
|
2014-07-23 23:33:06 +08:00
|
|
|
struct reset_control *rst;
|
2013-09-05 22:34:53 +08:00
|
|
|
struct uart_8250_dma dma;
|
2015-09-21 19:17:27 +08:00
|
|
|
|
|
|
|
unsigned int skip_autocfg:1;
|
2015-09-21 19:17:29 +08:00
|
|
|
unsigned int uart_16550_compatible:1;
|
2011-08-27 02:04:50 +08:00
|
|
|
};
|
|
|
|
|
2018-07-06 23:52:59 +08:00
|
|
|
static inline u32 dw8250_readl_ext(struct uart_port *p, int offset)
|
|
|
|
{
|
|
|
|
if (p->iotype == UPIO_MEM32BE)
|
|
|
|
return ioread32be(p->membase + offset);
|
|
|
|
return readl(p->membase + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void dw8250_writel_ext(struct uart_port *p, int offset, u32 reg)
|
|
|
|
{
|
|
|
|
if (p->iotype == UPIO_MEM32BE)
|
|
|
|
iowrite32be(reg, p->membase + offset);
|
|
|
|
else
|
|
|
|
writel(reg, p->membase + offset);
|
|
|
|
}
|
|
|
|
|
2013-08-17 04:50:15 +08:00
|
|
|
static inline int dw8250_modify_msr(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
|
|
|
struct dw8250_data *d = p->private_data;
|
|
|
|
|
2015-02-27 08:35:57 +08:00
|
|
|
/* Override any modem control signals if needed */
|
|
|
|
if (offset == UART_MSR) {
|
|
|
|
value |= d->msr_mask_on;
|
|
|
|
value &= ~d->msr_mask_off;
|
|
|
|
}
|
|
|
|
|
2013-08-17 04:50:15 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
serial: 8250_dw: Improve unwritable LCR workaround
When configured with UART_16550_COMPATIBLE=NO or in versions prior to
the introduction of this option, the Designware UART will ignore writes
to the LCR if the UART is busy. The current workaround saves a copy of
the last written LCR and re-writes it in the ISR for a special interrupt
that is raised when a write was ignored.
Unfortunately, interrupts are typically disabled prior to performing a
sequence of register writes that include the LCR so the point at which
the retry occurs is too late. An example is serial8250_do_set_termios()
where an ignored LCR write results in the baud divisor not being set and
instead a garbage character is sent out the transmitter.
Furthermore, since serial_port_out() offers no way to indicate failure,
a serious effort must be made to ensure that the LCR is actually updated
before returning back to the caller. This is difficult, however, as a
UART that was busy during the first attempt is likely to still be busy
when a subsequent attempt is made unless some extra action is taken.
This updated workaround reads back the LCR after each write to confirm
that the new value was accepted by the hardware. Should the hardware
ignore a write, the TX/RX FIFOs are cleared and the receive buffer read
before attempting to rewrite the LCR out of the hope that doing so will
force the UART into an idle state. While this may seem unnecessarily
aggressive, writes to the LCR are used to change the baud rate, parity,
stop bit, or data length so the data that may be lost is likely not
important. Admittedly, this is far from ideal but it seems to be the
best that can be done given the hardware limitations.
Lastly, the revised workaround doesn't touch the LCR in the ISR, so it
avoids the possibility of a "serial8250: too much work for irq" lock up.
This problem is rare in real situations but can be reproduced easily by
wiring up two UARTs and running the following commands.
# stty -F /dev/ttyS1 echo
# stty -F /dev/ttyS2 echo
# cat /dev/ttyS1 &
[1] 375
# echo asdf > /dev/ttyS1
asdf
[ 27.700000] serial8250: too much work for irq96
[ 27.700000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.740000] serial8250: too much work for irq96
Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Matt Porter <matt.porter@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-02 01:18:08 +08:00
|
|
|
static void dw8250_force_idle(struct uart_port *p)
|
|
|
|
{
|
2014-07-14 19:26:14 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(p);
|
|
|
|
|
|
|
|
serial8250_clear_and_reinit_fifos(up);
|
serial: 8250_dw: Improve unwritable LCR workaround
When configured with UART_16550_COMPATIBLE=NO or in versions prior to
the introduction of this option, the Designware UART will ignore writes
to the LCR if the UART is busy. The current workaround saves a copy of
the last written LCR and re-writes it in the ISR for a special interrupt
that is raised when a write was ignored.
Unfortunately, interrupts are typically disabled prior to performing a
sequence of register writes that include the LCR so the point at which
the retry occurs is too late. An example is serial8250_do_set_termios()
where an ignored LCR write results in the baud divisor not being set and
instead a garbage character is sent out the transmitter.
Furthermore, since serial_port_out() offers no way to indicate failure,
a serious effort must be made to ensure that the LCR is actually updated
before returning back to the caller. This is difficult, however, as a
UART that was busy during the first attempt is likely to still be busy
when a subsequent attempt is made unless some extra action is taken.
This updated workaround reads back the LCR after each write to confirm
that the new value was accepted by the hardware. Should the hardware
ignore a write, the TX/RX FIFOs are cleared and the receive buffer read
before attempting to rewrite the LCR out of the hope that doing so will
force the UART into an idle state. While this may seem unnecessarily
aggressive, writes to the LCR are used to change the baud rate, parity,
stop bit, or data length so the data that may be lost is likely not
important. Admittedly, this is far from ideal but it seems to be the
best that can be done given the hardware limitations.
Lastly, the revised workaround doesn't touch the LCR in the ISR, so it
avoids the possibility of a "serial8250: too much work for irq" lock up.
This problem is rare in real situations but can be reproduced easily by
wiring up two UARTs and running the following commands.
# stty -F /dev/ttyS1 echo
# stty -F /dev/ttyS2 echo
# cat /dev/ttyS1 &
[1] 375
# echo asdf > /dev/ttyS1
asdf
[ 27.700000] serial8250: too much work for irq96
[ 27.700000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.740000] serial8250: too much work for irq96
Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Matt Porter <matt.porter@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-02 01:18:08 +08:00
|
|
|
(void)p->serial_in(p, UART_RX);
|
|
|
|
}
|
|
|
|
|
2015-12-13 01:18:25 +08:00
|
|
|
static void dw8250_check_lcr(struct uart_port *p, int value)
|
2011-08-27 02:04:50 +08:00
|
|
|
{
|
2015-12-13 01:18:25 +08:00
|
|
|
void __iomem *offset = p->membase + (UART_LCR << p->regshift);
|
|
|
|
int tries = 1000;
|
serial: 8250_dw: Improve unwritable LCR workaround
When configured with UART_16550_COMPATIBLE=NO or in versions prior to
the introduction of this option, the Designware UART will ignore writes
to the LCR if the UART is busy. The current workaround saves a copy of
the last written LCR and re-writes it in the ISR for a special interrupt
that is raised when a write was ignored.
Unfortunately, interrupts are typically disabled prior to performing a
sequence of register writes that include the LCR so the point at which
the retry occurs is too late. An example is serial8250_do_set_termios()
where an ignored LCR write results in the baud divisor not being set and
instead a garbage character is sent out the transmitter.
Furthermore, since serial_port_out() offers no way to indicate failure,
a serious effort must be made to ensure that the LCR is actually updated
before returning back to the caller. This is difficult, however, as a
UART that was busy during the first attempt is likely to still be busy
when a subsequent attempt is made unless some extra action is taken.
This updated workaround reads back the LCR after each write to confirm
that the new value was accepted by the hardware. Should the hardware
ignore a write, the TX/RX FIFOs are cleared and the receive buffer read
before attempting to rewrite the LCR out of the hope that doing so will
force the UART into an idle state. While this may seem unnecessarily
aggressive, writes to the LCR are used to change the baud rate, parity,
stop bit, or data length so the data that may be lost is likely not
important. Admittedly, this is far from ideal but it seems to be the
best that can be done given the hardware limitations.
Lastly, the revised workaround doesn't touch the LCR in the ISR, so it
avoids the possibility of a "serial8250: too much work for irq" lock up.
This problem is rare in real situations but can be reproduced easily by
wiring up two UARTs and running the following commands.
# stty -F /dev/ttyS1 echo
# stty -F /dev/ttyS2 echo
# cat /dev/ttyS1 &
[1] 375
# echo asdf > /dev/ttyS1
asdf
[ 27.700000] serial8250: too much work for irq96
[ 27.700000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.740000] serial8250: too much work for irq96
Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Matt Porter <matt.porter@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-02 01:18:08 +08:00
|
|
|
|
|
|
|
/* Make sure LCR write wasn't ignored */
|
2015-12-13 01:18:25 +08:00
|
|
|
while (tries--) {
|
|
|
|
unsigned int lcr = p->serial_in(p, UART_LCR);
|
|
|
|
|
|
|
|
if ((value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR))
|
|
|
|
return;
|
|
|
|
|
|
|
|
dw8250_force_idle(p);
|
|
|
|
|
|
|
|
#ifdef CONFIG_64BIT
|
2016-05-02 17:19:46 +08:00
|
|
|
if (p->type == PORT_OCTEON)
|
|
|
|
__raw_writeq(value & 0xff, offset);
|
|
|
|
else
|
|
|
|
#endif
|
2015-12-13 01:18:25 +08:00
|
|
|
if (p->iotype == UPIO_MEM32)
|
|
|
|
writel(value, offset);
|
2015-12-13 01:18:27 +08:00
|
|
|
else if (p->iotype == UPIO_MEM32BE)
|
|
|
|
iowrite32be(value, offset);
|
2015-12-13 01:18:25 +08:00
|
|
|
else
|
|
|
|
writeb(value, offset);
|
serial: 8250_dw: Improve unwritable LCR workaround
When configured with UART_16550_COMPATIBLE=NO or in versions prior to
the introduction of this option, the Designware UART will ignore writes
to the LCR if the UART is busy. The current workaround saves a copy of
the last written LCR and re-writes it in the ISR for a special interrupt
that is raised when a write was ignored.
Unfortunately, interrupts are typically disabled prior to performing a
sequence of register writes that include the LCR so the point at which
the retry occurs is too late. An example is serial8250_do_set_termios()
where an ignored LCR write results in the baud divisor not being set and
instead a garbage character is sent out the transmitter.
Furthermore, since serial_port_out() offers no way to indicate failure,
a serious effort must be made to ensure that the LCR is actually updated
before returning back to the caller. This is difficult, however, as a
UART that was busy during the first attempt is likely to still be busy
when a subsequent attempt is made unless some extra action is taken.
This updated workaround reads back the LCR after each write to confirm
that the new value was accepted by the hardware. Should the hardware
ignore a write, the TX/RX FIFOs are cleared and the receive buffer read
before attempting to rewrite the LCR out of the hope that doing so will
force the UART into an idle state. While this may seem unnecessarily
aggressive, writes to the LCR are used to change the baud rate, parity,
stop bit, or data length so the data that may be lost is likely not
important. Admittedly, this is far from ideal but it seems to be the
best that can be done given the hardware limitations.
Lastly, the revised workaround doesn't touch the LCR in the ISR, so it
avoids the possibility of a "serial8250: too much work for irq" lock up.
This problem is rare in real situations but can be reproduced easily by
wiring up two UARTs and running the following commands.
# stty -F /dev/ttyS1 echo
# stty -F /dev/ttyS2 echo
# cat /dev/ttyS1 &
[1] 375
# echo asdf > /dev/ttyS1
asdf
[ 27.700000] serial8250: too much work for irq96
[ 27.700000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.740000] serial8250: too much work for irq96
Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Matt Porter <matt.porter@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-02 01:18:08 +08:00
|
|
|
}
|
2015-12-13 01:18:25 +08:00
|
|
|
/*
|
|
|
|
* FIXME: this deadlocks if port->lock is already held
|
|
|
|
* dev_err(p->dev, "Couldn't set LCR to %d\n", value);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2018-02-09 05:59:56 +08:00
|
|
|
/* Returns once the transmitter is empty or we run out of retries */
|
2018-03-16 08:42:00 +08:00
|
|
|
static void dw8250_tx_wait_empty(struct uart_port *p)
|
2018-02-09 05:59:56 +08:00
|
|
|
{
|
2018-03-16 08:42:00 +08:00
|
|
|
unsigned int tries = 20000;
|
|
|
|
unsigned int delay_threshold = tries - 1000;
|
2018-02-09 05:59:56 +08:00
|
|
|
unsigned int lsr;
|
|
|
|
|
|
|
|
while (tries--) {
|
|
|
|
lsr = readb (p->membase + (UART_LSR << p->regshift));
|
|
|
|
if (lsr & UART_LSR_TEMT)
|
|
|
|
break;
|
2018-03-16 08:42:00 +08:00
|
|
|
|
|
|
|
/* The device is first given a chance to empty without delay,
|
|
|
|
* to avoid slowdowns at high bitrates. If after 1000 tries
|
|
|
|
* the buffer has still not emptied, allow more time for low-
|
|
|
|
* speed links. */
|
|
|
|
if (tries < delay_threshold)
|
|
|
|
udelay (1);
|
2018-02-09 05:59:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 08:42:00 +08:00
|
|
|
static void dw8250_serial_out38x(struct uart_port *p, int offset, int value)
|
2015-12-13 01:18:25 +08:00
|
|
|
{
|
|
|
|
struct dw8250_data *d = p->private_data;
|
|
|
|
|
2018-02-09 05:59:56 +08:00
|
|
|
/* Allow the TX to drain before we reconfigure */
|
|
|
|
if (offset == UART_LCR)
|
2018-03-16 08:42:00 +08:00
|
|
|
dw8250_tx_wait_empty(p);
|
|
|
|
|
|
|
|
writeb(value, p->membase + (offset << p->regshift));
|
|
|
|
|
|
|
|
if (offset == UART_LCR && !d->uart_16550_compatible)
|
|
|
|
dw8250_check_lcr(p, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void dw8250_serial_out(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
|
|
|
struct dw8250_data *d = p->private_data;
|
2018-02-09 05:59:56 +08:00
|
|
|
|
2015-12-13 01:18:25 +08:00
|
|
|
writeb(value, p->membase + (offset << p->regshift));
|
|
|
|
|
|
|
|
if (offset == UART_LCR && !d->uart_16550_compatible)
|
|
|
|
dw8250_check_lcr(p, value);
|
2011-08-27 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int dw8250_serial_in(struct uart_port *p, int offset)
|
|
|
|
{
|
2013-08-17 04:50:15 +08:00
|
|
|
unsigned int value = readb(p->membase + (offset << p->regshift));
|
2011-08-27 02:04:50 +08:00
|
|
|
|
2013-08-17 04:50:15 +08:00
|
|
|
return dw8250_modify_msr(p, offset, value);
|
2011-08-27 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
2014-11-14 22:26:19 +08:00
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
static unsigned int dw8250_serial_inq(struct uart_port *p, int offset)
|
2013-06-20 04:37:27 +08:00
|
|
|
{
|
2014-11-14 22:26:19 +08:00
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
value = (u8)__raw_readq(p->membase + (offset << p->regshift));
|
|
|
|
|
|
|
|
return dw8250_modify_msr(p, offset, value);
|
2013-06-20 04:37:27 +08:00
|
|
|
}
|
|
|
|
|
2014-11-14 22:26:19 +08:00
|
|
|
static void dw8250_serial_outq(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
2015-12-13 01:18:25 +08:00
|
|
|
struct dw8250_data *d = p->private_data;
|
|
|
|
|
2014-11-14 22:26:19 +08:00
|
|
|
value &= 0xff;
|
|
|
|
__raw_writeq(value, p->membase + (offset << p->regshift));
|
|
|
|
/* Read back to ensure register write ordering. */
|
|
|
|
__raw_readq(p->membase + (UART_LCR << p->regshift));
|
|
|
|
|
2015-12-13 01:18:25 +08:00
|
|
|
if (offset == UART_LCR && !d->uart_16550_compatible)
|
|
|
|
dw8250_check_lcr(p, value);
|
2014-11-14 22:26:19 +08:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_64BIT */
|
|
|
|
|
2011-08-27 02:04:50 +08:00
|
|
|
static void dw8250_serial_out32(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
2015-12-13 01:18:25 +08:00
|
|
|
struct dw8250_data *d = p->private_data;
|
|
|
|
|
2013-08-17 04:50:15 +08:00
|
|
|
writel(value, p->membase + (offset << p->regshift));
|
serial: 8250_dw: Improve unwritable LCR workaround
When configured with UART_16550_COMPATIBLE=NO or in versions prior to
the introduction of this option, the Designware UART will ignore writes
to the LCR if the UART is busy. The current workaround saves a copy of
the last written LCR and re-writes it in the ISR for a special interrupt
that is raised when a write was ignored.
Unfortunately, interrupts are typically disabled prior to performing a
sequence of register writes that include the LCR so the point at which
the retry occurs is too late. An example is serial8250_do_set_termios()
where an ignored LCR write results in the baud divisor not being set and
instead a garbage character is sent out the transmitter.
Furthermore, since serial_port_out() offers no way to indicate failure,
a serious effort must be made to ensure that the LCR is actually updated
before returning back to the caller. This is difficult, however, as a
UART that was busy during the first attempt is likely to still be busy
when a subsequent attempt is made unless some extra action is taken.
This updated workaround reads back the LCR after each write to confirm
that the new value was accepted by the hardware. Should the hardware
ignore a write, the TX/RX FIFOs are cleared and the receive buffer read
before attempting to rewrite the LCR out of the hope that doing so will
force the UART into an idle state. While this may seem unnecessarily
aggressive, writes to the LCR are used to change the baud rate, parity,
stop bit, or data length so the data that may be lost is likely not
important. Admittedly, this is far from ideal but it seems to be the
best that can be done given the hardware limitations.
Lastly, the revised workaround doesn't touch the LCR in the ISR, so it
avoids the possibility of a "serial8250: too much work for irq" lock up.
This problem is rare in real situations but can be reproduced easily by
wiring up two UARTs and running the following commands.
# stty -F /dev/ttyS1 echo
# stty -F /dev/ttyS2 echo
# cat /dev/ttyS1 &
[1] 375
# echo asdf > /dev/ttyS1
asdf
[ 27.700000] serial8250: too much work for irq96
[ 27.700000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.740000] serial8250: too much work for irq96
Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Matt Porter <matt.porter@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-02 01:18:08 +08:00
|
|
|
|
2015-12-13 01:18:25 +08:00
|
|
|
if (offset == UART_LCR && !d->uart_16550_compatible)
|
|
|
|
dw8250_check_lcr(p, value);
|
2011-08-27 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int dw8250_serial_in32(struct uart_port *p, int offset)
|
|
|
|
{
|
2013-08-17 04:50:15 +08:00
|
|
|
unsigned int value = readl(p->membase + (offset << p->regshift));
|
2011-08-27 02:04:50 +08:00
|
|
|
|
2013-08-17 04:50:15 +08:00
|
|
|
return dw8250_modify_msr(p, offset, value);
|
2011-08-27 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
2015-12-13 01:18:26 +08:00
|
|
|
static void dw8250_serial_out32be(struct uart_port *p, int offset, int value)
|
|
|
|
{
|
|
|
|
struct dw8250_data *d = p->private_data;
|
|
|
|
|
|
|
|
iowrite32be(value, p->membase + (offset << p->regshift));
|
|
|
|
|
|
|
|
if (offset == UART_LCR && !d->uart_16550_compatible)
|
|
|
|
dw8250_check_lcr(p, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset)
|
|
|
|
{
|
|
|
|
unsigned int value = ioread32be(p->membase + (offset << p->regshift));
|
|
|
|
|
|
|
|
return dw8250_modify_msr(p, offset, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-27 02:04:50 +08:00
|
|
|
static int dw8250_handle_irq(struct uart_port *p)
|
|
|
|
{
|
2017-02-07 07:30:00 +08:00
|
|
|
struct uart_8250_port *up = up_to_u8250p(p);
|
2011-08-27 02:04:50 +08:00
|
|
|
struct dw8250_data *d = p->private_data;
|
|
|
|
unsigned int iir = p->serial_in(p, UART_IIR);
|
2017-02-07 07:30:00 +08:00
|
|
|
unsigned int status;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are ways to get Designware-based UARTs into a state where
|
|
|
|
* they are asserting UART_IIR_RX_TIMEOUT but there is no actual
|
|
|
|
* data available. If we see such a case then we'll do a bogus
|
|
|
|
* read. If we don't do this then the "RX TIMEOUT" interrupt will
|
|
|
|
* fire forever.
|
|
|
|
*
|
|
|
|
* This problem has only been observed so far when not in DMA mode
|
|
|
|
* so we limit the workaround only to non-DMA mode.
|
|
|
|
*/
|
|
|
|
if (!up->dma && ((iir & 0x3f) == UART_IIR_RX_TIMEOUT)) {
|
|
|
|
spin_lock_irqsave(&p->lock, flags);
|
|
|
|
status = p->serial_in(p, UART_LSR);
|
|
|
|
|
|
|
|
if (!(status & (UART_LSR_DR | UART_LSR_BI)))
|
|
|
|
(void) p->serial_in(p, UART_RX);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&p->lock, flags);
|
|
|
|
}
|
2011-08-27 02:04:50 +08:00
|
|
|
|
2016-02-15 23:38:45 +08:00
|
|
|
if (serial8250_handle_irq(p, iir))
|
2011-08-27 02:04:50 +08:00
|
|
|
return 1;
|
2016-02-15 23:38:45 +08:00
|
|
|
|
|
|
|
if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
|
serial: 8250_dw: Improve unwritable LCR workaround
When configured with UART_16550_COMPATIBLE=NO or in versions prior to
the introduction of this option, the Designware UART will ignore writes
to the LCR if the UART is busy. The current workaround saves a copy of
the last written LCR and re-writes it in the ISR for a special interrupt
that is raised when a write was ignored.
Unfortunately, interrupts are typically disabled prior to performing a
sequence of register writes that include the LCR so the point at which
the retry occurs is too late. An example is serial8250_do_set_termios()
where an ignored LCR write results in the baud divisor not being set and
instead a garbage character is sent out the transmitter.
Furthermore, since serial_port_out() offers no way to indicate failure,
a serious effort must be made to ensure that the LCR is actually updated
before returning back to the caller. This is difficult, however, as a
UART that was busy during the first attempt is likely to still be busy
when a subsequent attempt is made unless some extra action is taken.
This updated workaround reads back the LCR after each write to confirm
that the new value was accepted by the hardware. Should the hardware
ignore a write, the TX/RX FIFOs are cleared and the receive buffer read
before attempting to rewrite the LCR out of the hope that doing so will
force the UART into an idle state. While this may seem unnecessarily
aggressive, writes to the LCR are used to change the baud rate, parity,
stop bit, or data length so the data that may be lost is likely not
important. Admittedly, this is far from ideal but it seems to be the
best that can be done given the hardware limitations.
Lastly, the revised workaround doesn't touch the LCR in the ISR, so it
avoids the possibility of a "serial8250: too much work for irq" lock up.
This problem is rare in real situations but can be reproduced easily by
wiring up two UARTs and running the following commands.
# stty -F /dev/ttyS1 echo
# stty -F /dev/ttyS2 echo
# cat /dev/ttyS1 &
[1] 375
# echo asdf > /dev/ttyS1
asdf
[ 27.700000] serial8250: too much work for irq96
[ 27.700000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.740000] serial8250: too much work for irq96
Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Matt Porter <matt.porter@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-02 01:18:08 +08:00
|
|
|
/* Clear the USR */
|
2013-06-20 04:37:27 +08:00
|
|
|
(void)p->serial_in(p, d->usr_reg);
|
2011-08-27 02:04:50 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-10 21:58:28 +08:00
|
|
|
static void
|
|
|
|
dw8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old)
|
|
|
|
{
|
|
|
|
if (!state)
|
|
|
|
pm_runtime_get_sync(port->dev);
|
|
|
|
|
|
|
|
serial8250_do_pm(port, state, old);
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
pm_runtime_put_sync_suspend(port->dev);
|
|
|
|
}
|
|
|
|
|
2014-06-05 21:51:40 +08:00
|
|
|
static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
|
|
|
{
|
|
|
|
unsigned int baud = tty_termios_baud_rate(termios);
|
|
|
|
struct dw8250_data *d = p->private_data;
|
2017-03-09 14:41:16 +08:00
|
|
|
long rate;
|
2018-01-20 00:02:05 +08:00
|
|
|
int ret;
|
2014-06-05 21:51:40 +08:00
|
|
|
|
|
|
|
if (IS_ERR(d->clk) || !old)
|
|
|
|
goto out;
|
|
|
|
|
2018-01-20 00:02:05 +08:00
|
|
|
clk_disable_unprepare(d->clk);
|
|
|
|
rate = clk_round_rate(d->clk, baud * 16);
|
|
|
|
if (rate < 0)
|
|
|
|
ret = rate;
|
|
|
|
else if (rate == 0)
|
|
|
|
ret = -ENOENT;
|
|
|
|
else
|
2017-09-26 18:40:03 +08:00
|
|
|
ret = clk_set_rate(d->clk, rate);
|
2018-01-20 00:02:05 +08:00
|
|
|
clk_prepare_enable(d->clk);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
p->uartclk = rate;
|
2015-07-29 18:23:32 +08:00
|
|
|
|
2017-01-12 03:48:20 +08:00
|
|
|
out:
|
2015-07-29 18:23:32 +08:00
|
|
|
p->status &= ~UPSTAT_AUTOCTS;
|
|
|
|
if (termios->c_cflag & CRTSCTS)
|
|
|
|
p->status |= UPSTAT_AUTOCTS;
|
|
|
|
|
2014-06-05 21:51:40 +08:00
|
|
|
serial8250_do_set_termios(p, termios, old);
|
|
|
|
}
|
|
|
|
|
2016-11-11 02:07:56 +08:00
|
|
|
static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios)
|
|
|
|
{
|
|
|
|
struct uart_8250_port *up = up_to_u8250p(p);
|
|
|
|
unsigned int mcr = p->serial_in(p, UART_MCR);
|
|
|
|
|
|
|
|
if (up->capabilities & UART_CAP_IRDA) {
|
|
|
|
if (termios->c_line == N_IRDA)
|
|
|
|
mcr |= DW_UART_MCR_SIRE;
|
|
|
|
else
|
|
|
|
mcr &= ~DW_UART_MCR_SIRE;
|
|
|
|
|
|
|
|
p->serial_out(p, UART_MCR, mcr);
|
|
|
|
}
|
|
|
|
serial8250_do_set_ldisc(p, termios);
|
|
|
|
}
|
|
|
|
|
2015-09-21 19:17:30 +08:00
|
|
|
/*
|
|
|
|
* dw8250_fallback_dma_filter will prevent the UART from getting just any free
|
|
|
|
* channel on platforms that have DMA engines, but don't have any channels
|
|
|
|
* assigned to the UART.
|
|
|
|
*
|
|
|
|
* REVISIT: This is a work around for limitation in the DMA Engine API. Once the
|
|
|
|
* core problem is fixed, this function is no longer needed.
|
|
|
|
*/
|
|
|
|
static bool dw8250_fallback_dma_filter(struct dma_chan *chan, void *param)
|
2013-09-05 22:34:54 +08:00
|
|
|
{
|
2014-08-20 01:29:22 +08:00
|
|
|
return false;
|
2013-09-05 22:34:54 +08:00
|
|
|
}
|
|
|
|
|
2015-05-26 20:59:32 +08:00
|
|
|
static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
|
|
|
|
{
|
2015-09-21 19:17:31 +08:00
|
|
|
return param == chan->device->dev->parent;
|
2015-05-26 20:59:32 +08:00
|
|
|
}
|
|
|
|
|
2015-09-21 19:17:28 +08:00
|
|
|
static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
|
2013-01-10 17:25:10 +08:00
|
|
|
{
|
2015-09-21 19:17:28 +08:00
|
|
|
if (p->dev->of_node) {
|
|
|
|
struct device_node *np = p->dev->of_node;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
/* get index of serial line, if found in DT aliases */
|
|
|
|
id = of_alias_get_id(np, "serial");
|
|
|
|
if (id >= 0)
|
|
|
|
p->line = id;
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
if (of_device_is_compatible(np, "cavium,octeon-3860-uart")) {
|
|
|
|
p->serial_in = dw8250_serial_inq;
|
|
|
|
p->serial_out = dw8250_serial_outq;
|
|
|
|
p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
|
|
|
|
p->type = PORT_OCTEON;
|
|
|
|
data->usr_reg = 0x27;
|
|
|
|
data->skip_autocfg = true;
|
|
|
|
}
|
|
|
|
#endif
|
2015-12-13 01:18:26 +08:00
|
|
|
if (of_device_is_big_endian(p->dev->of_node)) {
|
|
|
|
p->iotype = UPIO_MEM32BE;
|
|
|
|
p->serial_in = dw8250_serial_in32be;
|
|
|
|
p->serial_out = dw8250_serial_out32be;
|
|
|
|
}
|
2018-03-16 08:42:00 +08:00
|
|
|
if (of_device_is_compatible(np, "marvell,armada-38x-uart"))
|
|
|
|
p->serial_out = dw8250_serial_out38x;
|
|
|
|
|
2018-03-01 19:41:29 +08:00
|
|
|
} else if (acpi_dev_present("APMC0D08", NULL, -1)) {
|
|
|
|
p->iotype = UPIO_MEM32;
|
|
|
|
p->regshift = 2;
|
|
|
|
p->serial_in = dw8250_serial_in32;
|
|
|
|
data->uart_16550_compatible = true;
|
2015-09-21 19:17:28 +08:00
|
|
|
}
|
2013-04-10 21:58:29 +08:00
|
|
|
|
2015-05-26 20:59:32 +08:00
|
|
|
/* Platforms with iDMA */
|
2015-09-21 19:17:28 +08:00
|
|
|
if (platform_get_resource_byname(to_platform_device(p->dev),
|
2015-05-26 20:59:32 +08:00
|
|
|
IORESOURCE_MEM, "lpss_priv")) {
|
2015-09-21 19:17:28 +08:00
|
|
|
data->dma.rx_param = p->dev->parent;
|
|
|
|
data->dma.tx_param = p->dev->parent;
|
2015-05-26 20:59:32 +08:00
|
|
|
data->dma.fn = dw8250_idma_filter;
|
|
|
|
}
|
2013-01-10 17:25:10 +08:00
|
|
|
}
|
|
|
|
|
2015-09-21 19:17:32 +08:00
|
|
|
static void dw8250_setup_port(struct uart_port *p)
|
|
|
|
{
|
|
|
|
struct uart_8250_port *up = up_to_u8250p(p);
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the Component Version Register returns zero, we know that
|
|
|
|
* ADDITIONAL_FEATURES are not enabled. No need to go any further.
|
|
|
|
*/
|
2018-07-06 23:52:59 +08:00
|
|
|
reg = dw8250_readl_ext(p, DW_UART_UCV);
|
2015-09-21 19:17:32 +08:00
|
|
|
if (!reg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dev_dbg(p->dev, "Designware UART version %c.%c%c\n",
|
|
|
|
(reg >> 24) & 0xff, (reg >> 16) & 0xff, (reg >> 8) & 0xff);
|
|
|
|
|
2018-07-06 23:52:59 +08:00
|
|
|
reg = dw8250_readl_ext(p, DW_UART_CPR);
|
2015-09-21 19:17:32 +08:00
|
|
|
if (!reg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Select the type based on fifo */
|
|
|
|
if (reg & DW_UART_CPR_FIFO_MODE) {
|
|
|
|
p->type = PORT_16550A;
|
|
|
|
p->flags |= UPF_FIXED_TYPE;
|
|
|
|
p->fifosize = DW_UART_CPR_FIFO_SIZE(reg);
|
|
|
|
up->capabilities = UART_CAP_FIFO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reg & DW_UART_CPR_AFCE_MODE)
|
|
|
|
up->capabilities |= UART_CAP_AFE;
|
2016-11-11 02:07:56 +08:00
|
|
|
|
|
|
|
if (reg & DW_UART_CPR_SIR_MODE)
|
|
|
|
up->capabilities |= UART_CAP_IRDA;
|
2015-09-21 19:17:32 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 02:21:50 +08:00
|
|
|
static int dw8250_probe(struct platform_device *pdev)
|
2011-08-27 02:04:50 +08:00
|
|
|
{
|
2012-07-12 19:59:50 +08:00
|
|
|
struct uart_8250_port uart = {};
|
2011-08-27 02:04:50 +08:00
|
|
|
struct resource *regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2015-03-03 23:11:14 +08:00
|
|
|
int irq = platform_get_irq(pdev, 0);
|
2015-09-21 19:17:24 +08:00
|
|
|
struct uart_port *p = &uart.port;
|
2016-09-01 10:24:19 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2011-08-27 02:04:50 +08:00
|
|
|
struct dw8250_data *data;
|
2013-01-10 17:25:08 +08:00
|
|
|
int err;
|
2015-09-21 19:17:25 +08:00
|
|
|
u32 val;
|
2011-08-27 02:04:50 +08:00
|
|
|
|
2015-03-03 23:11:14 +08:00
|
|
|
if (!regs) {
|
2016-09-01 10:24:19 +08:00
|
|
|
dev_err(dev, "no registers defined\n");
|
2011-08-27 02:04:50 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-03-03 23:11:14 +08:00
|
|
|
if (irq < 0) {
|
|
|
|
if (irq != -EPROBE_DEFER)
|
2016-09-01 10:24:19 +08:00
|
|
|
dev_err(dev, "cannot get irq\n");
|
2015-03-03 23:11:14 +08:00
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
2015-09-21 19:17:24 +08:00
|
|
|
spin_lock_init(&p->lock);
|
|
|
|
p->mapbase = regs->start;
|
|
|
|
p->irq = irq;
|
|
|
|
p->handle_irq = dw8250_handle_irq;
|
|
|
|
p->pm = dw8250_do_pm;
|
|
|
|
p->type = PORT_8250;
|
2015-09-21 19:17:33 +08:00
|
|
|
p->flags = UPF_SHARE_IRQ | UPF_FIXED_PORT;
|
2016-09-01 10:24:19 +08:00
|
|
|
p->dev = dev;
|
2015-09-21 19:17:24 +08:00
|
|
|
p->iotype = UPIO_MEM;
|
|
|
|
p->serial_in = dw8250_serial_in;
|
|
|
|
p->serial_out = dw8250_serial_out;
|
2016-11-11 02:07:56 +08:00
|
|
|
p->set_ldisc = dw8250_set_ldisc;
|
2017-01-12 03:48:20 +08:00
|
|
|
p->set_termios = dw8250_set_termios;
|
2015-09-21 19:17:24 +08:00
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
p->membase = devm_ioremap(dev, regs->start, resource_size(regs));
|
2015-09-21 19:17:24 +08:00
|
|
|
if (!p->membase)
|
2013-01-10 17:25:07 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
|
2013-03-29 07:15:49 +08:00
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-09-21 19:17:30 +08:00
|
|
|
data->dma.fn = dw8250_fallback_dma_filter;
|
2013-06-20 04:37:27 +08:00
|
|
|
data->usr_reg = DW_UART_USR;
|
2015-09-21 19:17:24 +08:00
|
|
|
p->private_data = data;
|
2015-03-18 18:55:13 +08:00
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
data->uart_16550_compatible = device_property_read_bool(dev,
|
2015-09-21 19:17:29 +08:00
|
|
|
"snps,uart-16550-compatible");
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
err = device_property_read_u32(dev, "reg-shift", &val);
|
2015-09-21 19:17:25 +08:00
|
|
|
if (!err)
|
|
|
|
p->regshift = val;
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
err = device_property_read_u32(dev, "reg-io-width", &val);
|
2015-09-21 19:17:25 +08:00
|
|
|
if (!err && val == 4) {
|
|
|
|
p->iotype = UPIO_MEM32;
|
|
|
|
p->serial_in = dw8250_serial_in32;
|
|
|
|
p->serial_out = dw8250_serial_out32;
|
|
|
|
}
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
if (device_property_read_bool(dev, "dcd-override")) {
|
2015-09-21 19:17:25 +08:00
|
|
|
/* Always report DCD as active */
|
|
|
|
data->msr_mask_on |= UART_MSR_DCD;
|
|
|
|
data->msr_mask_off |= UART_MSR_DDCD;
|
|
|
|
}
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
if (device_property_read_bool(dev, "dsr-override")) {
|
2015-09-21 19:17:25 +08:00
|
|
|
/* Always report DSR as active */
|
|
|
|
data->msr_mask_on |= UART_MSR_DSR;
|
|
|
|
data->msr_mask_off |= UART_MSR_DDSR;
|
|
|
|
}
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
if (device_property_read_bool(dev, "cts-override")) {
|
2015-09-21 19:17:25 +08:00
|
|
|
/* Always report CTS as active */
|
|
|
|
data->msr_mask_on |= UART_MSR_CTS;
|
|
|
|
data->msr_mask_off |= UART_MSR_DCTS;
|
|
|
|
}
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
if (device_property_read_bool(dev, "ri-override")) {
|
2015-09-21 19:17:25 +08:00
|
|
|
/* Always report Ring indicator as inactive */
|
|
|
|
data->msr_mask_off |= UART_MSR_RI;
|
|
|
|
data->msr_mask_off |= UART_MSR_TERI;
|
|
|
|
}
|
|
|
|
|
2015-03-18 18:55:13 +08:00
|
|
|
/* Always ask for fixed clock rate from a property. */
|
2016-09-01 10:24:19 +08:00
|
|
|
device_property_read_u32(dev, "clock-frequency", &p->uartclk);
|
2015-03-18 18:55:13 +08:00
|
|
|
|
|
|
|
/* If there is separate baudclk, get the rate from it. */
|
2016-09-01 10:24:19 +08:00
|
|
|
data->clk = devm_clk_get(dev, "baudclk");
|
serial: 8250_dw: Add support for deferred probing
The 8250_dw driver fails to probe if the specified clock isn't
registered at probe time. Even if a clock frequency is given,
the required clock might be gated because it wasn't properly
enabled.
This happened to me when the device is registered through DT,
and the clock was part of an MFD, the PRCM found on A31 and A23
SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE,
which happen almost immediately after the kernel starts, the
clocks are registered as sub-devices of the PRCM MFD platform
device. Even though devices are registered in the order they are
found in the DT, the drivers are registered in a different,
arbitrary order. It is possible that the 8250_dw driver is
registered, and thus associated with the device and probed, before
the clock driver is registered and probed.
8250_dw then reports unable to get the clock, and fails. Without
a working console, the kernel panics.
This patch adds support for deferred probe handling for the clock
and reset controller. It also fixes the cleanup path if
serial8250_register_8250_port fails.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-23 23:33:07 +08:00
|
|
|
if (IS_ERR(data->clk) && PTR_ERR(data->clk) != -EPROBE_DEFER)
|
2016-09-01 10:24:19 +08:00
|
|
|
data->clk = devm_clk_get(dev, NULL);
|
serial: 8250_dw: Add support for deferred probing
The 8250_dw driver fails to probe if the specified clock isn't
registered at probe time. Even if a clock frequency is given,
the required clock might be gated because it wasn't properly
enabled.
This happened to me when the device is registered through DT,
and the clock was part of an MFD, the PRCM found on A31 and A23
SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE,
which happen almost immediately after the kernel starts, the
clocks are registered as sub-devices of the PRCM MFD platform
device. Even though devices are registered in the order they are
found in the DT, the drivers are registered in a different,
arbitrary order. It is possible that the 8250_dw driver is
registered, and thus associated with the device and probed, before
the clock driver is registered and probed.
8250_dw then reports unable to get the clock, and fails. Without
a working console, the kernel panics.
This patch adds support for deferred probe handling for the clock
and reset controller. It also fixes the cleanup path if
serial8250_register_8250_port fails.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-23 23:33:07 +08:00
|
|
|
if (IS_ERR(data->clk) && PTR_ERR(data->clk) == -EPROBE_DEFER)
|
|
|
|
return -EPROBE_DEFER;
|
2015-03-18 18:55:13 +08:00
|
|
|
if (!IS_ERR_OR_NULL(data->clk)) {
|
2014-06-16 21:25:17 +08:00
|
|
|
err = clk_prepare_enable(data->clk);
|
|
|
|
if (err)
|
2016-09-01 10:24:19 +08:00
|
|
|
dev_warn(dev, "could not enable optional baudclk: %d\n",
|
2014-06-16 21:25:17 +08:00
|
|
|
err);
|
|
|
|
else
|
2015-09-21 19:17:24 +08:00
|
|
|
p->uartclk = clk_get_rate(data->clk);
|
2014-06-16 21:25:17 +08:00
|
|
|
}
|
|
|
|
|
2015-03-18 18:55:13 +08:00
|
|
|
/* If no clock rate is defined, fail. */
|
2015-09-21 19:17:24 +08:00
|
|
|
if (!p->uartclk) {
|
2016-09-01 10:24:19 +08:00
|
|
|
dev_err(dev, "clock rate not defined\n");
|
2017-12-06 23:46:12 +08:00
|
|
|
err = -EINVAL;
|
|
|
|
goto err_clk;
|
2015-03-18 18:55:13 +08:00
|
|
|
}
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
data->pclk = devm_clk_get(dev, "apb_pclk");
|
2016-08-24 16:33:33 +08:00
|
|
|
if (IS_ERR(data->pclk) && PTR_ERR(data->pclk) == -EPROBE_DEFER) {
|
serial: 8250_dw: Add support for deferred probing
The 8250_dw driver fails to probe if the specified clock isn't
registered at probe time. Even if a clock frequency is given,
the required clock might be gated because it wasn't properly
enabled.
This happened to me when the device is registered through DT,
and the clock was part of an MFD, the PRCM found on A31 and A23
SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE,
which happen almost immediately after the kernel starts, the
clocks are registered as sub-devices of the PRCM MFD platform
device. Even though devices are registered in the order they are
found in the DT, the drivers are registered in a different,
arbitrary order. It is possible that the 8250_dw driver is
registered, and thus associated with the device and probed, before
the clock driver is registered and probed.
8250_dw then reports unable to get the clock, and fails. Without
a working console, the kernel panics.
This patch adds support for deferred probe handling for the clock
and reset controller. It also fixes the cleanup path if
serial8250_register_8250_port fails.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-23 23:33:07 +08:00
|
|
|
err = -EPROBE_DEFER;
|
|
|
|
goto err_clk;
|
|
|
|
}
|
2014-06-16 21:25:17 +08:00
|
|
|
if (!IS_ERR(data->pclk)) {
|
|
|
|
err = clk_prepare_enable(data->pclk);
|
|
|
|
if (err) {
|
2016-09-01 10:24:19 +08:00
|
|
|
dev_err(dev, "could not enable apb_pclk\n");
|
serial: 8250_dw: Add support for deferred probing
The 8250_dw driver fails to probe if the specified clock isn't
registered at probe time. Even if a clock frequency is given,
the required clock might be gated because it wasn't properly
enabled.
This happened to me when the device is registered through DT,
and the clock was part of an MFD, the PRCM found on A31 and A23
SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE,
which happen almost immediately after the kernel starts, the
clocks are registered as sub-devices of the PRCM MFD platform
device. Even though devices are registered in the order they are
found in the DT, the drivers are registered in a different,
arbitrary order. It is possible that the 8250_dw driver is
registered, and thus associated with the device and probed, before
the clock driver is registered and probed.
8250_dw then reports unable to get the clock, and fails. Without
a working console, the kernel panics.
This patch adds support for deferred probe handling for the clock
and reset controller. It also fixes the cleanup path if
serial8250_register_8250_port fails.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-23 23:33:07 +08:00
|
|
|
goto err_clk;
|
2014-06-16 21:25:17 +08:00
|
|
|
}
|
2013-03-29 07:15:49 +08:00
|
|
|
}
|
|
|
|
|
2017-07-19 23:26:28 +08:00
|
|
|
data->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
|
2017-03-15 19:31:50 +08:00
|
|
|
if (IS_ERR(data->rst)) {
|
|
|
|
err = PTR_ERR(data->rst);
|
serial: 8250_dw: Add support for deferred probing
The 8250_dw driver fails to probe if the specified clock isn't
registered at probe time. Even if a clock frequency is given,
the required clock might be gated because it wasn't properly
enabled.
This happened to me when the device is registered through DT,
and the clock was part of an MFD, the PRCM found on A31 and A23
SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE,
which happen almost immediately after the kernel starts, the
clocks are registered as sub-devices of the PRCM MFD platform
device. Even though devices are registered in the order they are
found in the DT, the drivers are registered in a different,
arbitrary order. It is possible that the 8250_dw driver is
registered, and thus associated with the device and probed, before
the clock driver is registered and probed.
8250_dw then reports unable to get the clock, and fails. Without
a working console, the kernel panics.
This patch adds support for deferred probe handling for the clock
and reset controller. It also fixes the cleanup path if
serial8250_register_8250_port fails.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-23 23:33:07 +08:00
|
|
|
goto err_pclk;
|
|
|
|
}
|
2017-03-15 19:31:50 +08:00
|
|
|
reset_control_deassert(data->rst);
|
2014-07-23 23:33:06 +08:00
|
|
|
|
2015-09-21 19:17:28 +08:00
|
|
|
dw8250_quirks(p, data);
|
2011-08-27 02:04:50 +08:00
|
|
|
|
2015-09-21 19:17:29 +08:00
|
|
|
/* If the Busy Functionality is not implemented, don't handle it */
|
2015-12-13 01:18:25 +08:00
|
|
|
if (data->uart_16550_compatible)
|
2015-09-21 19:17:29 +08:00
|
|
|
p->handle_irq = NULL;
|
|
|
|
|
2015-09-21 19:17:27 +08:00
|
|
|
if (!data->skip_autocfg)
|
2015-09-21 19:17:32 +08:00
|
|
|
dw8250_setup_port(p);
|
2015-09-21 19:17:27 +08:00
|
|
|
|
2018-05-10 22:13:56 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
uart.capabilities |= UART_CAP_RPM;
|
|
|
|
#endif
|
|
|
|
|
2015-09-21 19:17:26 +08:00
|
|
|
/* If we have a valid fifosize, try hooking up DMA */
|
|
|
|
if (p->fifosize) {
|
|
|
|
data->dma.rxconf.src_maxburst = p->fifosize / 4;
|
|
|
|
data->dma.txconf.dst_maxburst = p->fifosize / 4;
|
|
|
|
uart.dma = &data->dma;
|
|
|
|
}
|
|
|
|
|
2012-07-12 19:59:50 +08:00
|
|
|
data->line = serial8250_register_8250_port(&uart);
|
serial: 8250_dw: Add support for deferred probing
The 8250_dw driver fails to probe if the specified clock isn't
registered at probe time. Even if a clock frequency is given,
the required clock might be gated because it wasn't properly
enabled.
This happened to me when the device is registered through DT,
and the clock was part of an MFD, the PRCM found on A31 and A23
SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE,
which happen almost immediately after the kernel starts, the
clocks are registered as sub-devices of the PRCM MFD platform
device. Even though devices are registered in the order they are
found in the DT, the drivers are registered in a different,
arbitrary order. It is possible that the 8250_dw driver is
registered, and thus associated with the device and probed, before
the clock driver is registered and probed.
8250_dw then reports unable to get the clock, and fails. Without
a working console, the kernel panics.
This patch adds support for deferred probe handling for the clock
and reset controller. It also fixes the cleanup path if
serial8250_register_8250_port fails.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-23 23:33:07 +08:00
|
|
|
if (data->line < 0) {
|
|
|
|
err = data->line;
|
|
|
|
goto err_reset;
|
|
|
|
}
|
2011-08-27 02:04:50 +08:00
|
|
|
|
|
|
|
platform_set_drvdata(pdev, data);
|
|
|
|
|
2016-09-01 10:24:19 +08:00
|
|
|
pm_runtime_set_active(dev);
|
|
|
|
pm_runtime_enable(dev);
|
2013-04-10 21:58:28 +08:00
|
|
|
|
2011-08-27 02:04:50 +08:00
|
|
|
return 0;
|
serial: 8250_dw: Add support for deferred probing
The 8250_dw driver fails to probe if the specified clock isn't
registered at probe time. Even if a clock frequency is given,
the required clock might be gated because it wasn't properly
enabled.
This happened to me when the device is registered through DT,
and the clock was part of an MFD, the PRCM found on A31 and A23
SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE,
which happen almost immediately after the kernel starts, the
clocks are registered as sub-devices of the PRCM MFD platform
device. Even though devices are registered in the order they are
found in the DT, the drivers are registered in a different,
arbitrary order. It is possible that the 8250_dw driver is
registered, and thus associated with the device and probed, before
the clock driver is registered and probed.
8250_dw then reports unable to get the clock, and fails. Without
a working console, the kernel panics.
This patch adds support for deferred probe handling for the clock
and reset controller. It also fixes the cleanup path if
serial8250_register_8250_port fails.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-23 23:33:07 +08:00
|
|
|
|
|
|
|
err_reset:
|
2017-03-15 19:31:50 +08:00
|
|
|
reset_control_assert(data->rst);
|
serial: 8250_dw: Add support for deferred probing
The 8250_dw driver fails to probe if the specified clock isn't
registered at probe time. Even if a clock frequency is given,
the required clock might be gated because it wasn't properly
enabled.
This happened to me when the device is registered through DT,
and the clock was part of an MFD, the PRCM found on A31 and A23
SoCs. Unlike core clocks that are registered with OF_CLK_DECLARE,
which happen almost immediately after the kernel starts, the
clocks are registered as sub-devices of the PRCM MFD platform
device. Even though devices are registered in the order they are
found in the DT, the drivers are registered in a different,
arbitrary order. It is possible that the 8250_dw driver is
registered, and thus associated with the device and probed, before
the clock driver is registered and probed.
8250_dw then reports unable to get the clock, and fails. Without
a working console, the kernel panics.
This patch adds support for deferred probe handling for the clock
and reset controller. It also fixes the cleanup path if
serial8250_register_8250_port fails.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-07-23 23:33:07 +08:00
|
|
|
|
|
|
|
err_pclk:
|
|
|
|
if (!IS_ERR(data->pclk))
|
|
|
|
clk_disable_unprepare(data->pclk);
|
|
|
|
|
|
|
|
err_clk:
|
|
|
|
if (!IS_ERR(data->clk))
|
|
|
|
clk_disable_unprepare(data->clk);
|
|
|
|
|
|
|
|
return err;
|
2011-08-27 02:04:50 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:18 +08:00
|
|
|
static int dw8250_remove(struct platform_device *pdev)
|
2011-08-27 02:04:50 +08:00
|
|
|
{
|
|
|
|
struct dw8250_data *data = platform_get_drvdata(pdev);
|
|
|
|
|
2013-04-10 21:58:28 +08:00
|
|
|
pm_runtime_get_sync(&pdev->dev);
|
|
|
|
|
2011-08-27 02:04:50 +08:00
|
|
|
serial8250_unregister_port(data->line);
|
|
|
|
|
2017-03-15 19:31:50 +08:00
|
|
|
reset_control_assert(data->rst);
|
2014-07-23 23:33:06 +08:00
|
|
|
|
2014-06-16 21:25:17 +08:00
|
|
|
if (!IS_ERR(data->pclk))
|
|
|
|
clk_disable_unprepare(data->pclk);
|
|
|
|
|
2013-03-29 07:15:49 +08:00
|
|
|
if (!IS_ERR(data->clk))
|
|
|
|
clk_disable_unprepare(data->clk);
|
|
|
|
|
2013-04-10 21:58:28 +08:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
pm_runtime_put_noidle(&pdev->dev);
|
|
|
|
|
2011-08-27 02:04:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-16 20:55:57 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2013-04-10 21:58:28 +08:00
|
|
|
static int dw8250_suspend(struct device *dev)
|
2012-10-15 17:25:58 +08:00
|
|
|
{
|
2013-04-10 21:58:28 +08:00
|
|
|
struct dw8250_data *data = dev_get_drvdata(dev);
|
2012-10-15 17:25:58 +08:00
|
|
|
|
|
|
|
serial8250_suspend_port(data->line);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-10 21:58:28 +08:00
|
|
|
static int dw8250_resume(struct device *dev)
|
2012-10-15 17:25:58 +08:00
|
|
|
{
|
2013-04-10 21:58:28 +08:00
|
|
|
struct dw8250_data *data = dev_get_drvdata(dev);
|
2012-10-15 17:25:58 +08:00
|
|
|
|
|
|
|
serial8250_resume_port(data->line);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-16 20:55:57 +08:00
|
|
|
#endif /* CONFIG_PM_SLEEP */
|
2012-10-15 17:25:58 +08:00
|
|
|
|
2014-12-13 07:41:36 +08:00
|
|
|
#ifdef CONFIG_PM
|
2013-04-10 21:58:28 +08:00
|
|
|
static int dw8250_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct dw8250_data *data = dev_get_drvdata(dev);
|
|
|
|
|
2013-05-07 19:27:16 +08:00
|
|
|
if (!IS_ERR(data->clk))
|
|
|
|
clk_disable_unprepare(data->clk);
|
2013-04-10 21:58:28 +08:00
|
|
|
|
2014-06-16 21:25:17 +08:00
|
|
|
if (!IS_ERR(data->pclk))
|
|
|
|
clk_disable_unprepare(data->pclk);
|
|
|
|
|
2013-04-10 21:58:28 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dw8250_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct dw8250_data *data = dev_get_drvdata(dev);
|
|
|
|
|
2014-06-16 21:25:17 +08:00
|
|
|
if (!IS_ERR(data->pclk))
|
|
|
|
clk_prepare_enable(data->pclk);
|
|
|
|
|
2013-05-07 19:27:16 +08:00
|
|
|
if (!IS_ERR(data->clk))
|
|
|
|
clk_prepare_enable(data->clk);
|
2013-04-10 21:58:28 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct dev_pm_ops dw8250_pm_ops = {
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(dw8250_suspend, dw8250_resume)
|
|
|
|
SET_RUNTIME_PM_OPS(dw8250_runtime_suspend, dw8250_runtime_resume, NULL)
|
|
|
|
};
|
|
|
|
|
2013-01-10 17:25:08 +08:00
|
|
|
static const struct of_device_id dw8250_of_match[] = {
|
2011-08-27 02:04:50 +08:00
|
|
|
{ .compatible = "snps,dw-apb-uart" },
|
2013-06-20 04:37:27 +08:00
|
|
|
{ .compatible = "cavium,octeon-3860-uart" },
|
2018-03-16 08:42:00 +08:00
|
|
|
{ .compatible = "marvell,armada-38x-uart" },
|
2011-08-27 02:04:50 +08:00
|
|
|
{ /* Sentinel */ }
|
|
|
|
};
|
2013-01-10 17:25:08 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, dw8250_of_match);
|
2011-08-27 02:04:50 +08:00
|
|
|
|
2013-01-10 17:25:10 +08:00
|
|
|
static const struct acpi_device_id dw8250_acpi_match[] = {
|
2013-04-10 21:58:29 +08:00
|
|
|
{ "INT33C4", 0 },
|
|
|
|
{ "INT33C5", 0 },
|
2013-12-10 18:56:59 +08:00
|
|
|
{ "INT3434", 0 },
|
|
|
|
{ "INT3435", 0 },
|
2014-06-05 21:51:40 +08:00
|
|
|
{ "80860F0A", 0 },
|
2014-08-19 21:34:49 +08:00
|
|
|
{ "8086228A", 0 },
|
2014-12-06 09:45:57 +08:00
|
|
|
{ "APMC0D08", 0},
|
2015-03-09 17:10:13 +08:00
|
|
|
{ "AMD0020", 0 },
|
2016-03-11 09:40:11 +08:00
|
|
|
{ "AMDI0020", 0 },
|
2016-08-31 11:29:12 +08:00
|
|
|
{ "HISI0031", 0 },
|
2013-01-10 17:25:10 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, dw8250_acpi_match);
|
|
|
|
|
2011-08-27 02:04:50 +08:00
|
|
|
static struct platform_driver dw8250_platform_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "dw-apb-uart",
|
2013-04-10 21:58:28 +08:00
|
|
|
.pm = &dw8250_pm_ops,
|
2013-01-10 17:25:08 +08:00
|
|
|
.of_match_table = dw8250_of_match,
|
2013-01-10 17:25:10 +08:00
|
|
|
.acpi_match_table = ACPI_PTR(dw8250_acpi_match),
|
2011-08-27 02:04:50 +08:00
|
|
|
},
|
|
|
|
.probe = dw8250_probe,
|
2012-11-20 02:21:34 +08:00
|
|
|
.remove = dw8250_remove,
|
2011-08-27 02:04:50 +08:00
|
|
|
};
|
|
|
|
|
2011-11-28 19:22:15 +08:00
|
|
|
module_platform_driver(dw8250_platform_driver);
|
2011-08-27 02:04:50 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Jamie Iles");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Synopsys DesignWare 8250 serial port driver");
|
2015-02-04 21:03:48 +08:00
|
|
|
MODULE_ALIAS("platform:dw-apb-uart");
|