Skip to content

Commit fecf27a

Browse files
hpetergregkh
authored andcommitted
serial: 8250_pci: add RS485 for F81504/508/512
Add RS485 control for Fintek F81504/508/512 F81504/508/512 can control their RTS with H/W mode. PCI configuration space for each port is 0x40 + idx * 8 + 7. When it set with 0x01, it's configured with RS232 mode. RTS is controlled by MCR. When it set with 0x11, it's configured with RS485 mode. RTS is controlled by H/W, RTS low with idle & RX, high with TX. When it set with 0x31, it's configured with RS485 mode. RTS is controlled by H/W, RTS high with idle & RX, low with TX. We will force 0x01 on pci_fintek_setup(). Signed-off-by: Peter Hung <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a3a10ce commit fecf27a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

drivers/tty/serial/8250/8250_pci.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,11 +1685,60 @@ pci_brcm_trumanage_setup(struct serial_private *priv,
16851685
return ret;
16861686
}
16871687

1688+
/* RTS will control by MCR if this bit is 0 */
1689+
#define FINTEK_RTS_CONTROL_BY_HW BIT(4)
1690+
/* only worked with FINTEK_RTS_CONTROL_BY_HW on */
1691+
#define FINTEK_RTS_INVERT BIT(5)
1692+
1693+
/* We should do proper H/W transceiver setting before change to RS485 mode */
1694+
static int pci_fintek_rs485_config(struct uart_port *port,
1695+
struct serial_rs485 *rs485)
1696+
{
1697+
u8 setting;
1698+
u8 *index = (u8 *) port->private_data;
1699+
struct pci_dev *pci_dev = container_of(port->dev, struct pci_dev,
1700+
dev);
1701+
1702+
pci_read_config_byte(pci_dev, 0x40 + 8 * *index + 7, &setting);
1703+
1704+
if (rs485->flags & SER_RS485_ENABLED)
1705+
memset(rs485->padding, 0, sizeof(rs485->padding));
1706+
else
1707+
memset(rs485, 0, sizeof(*rs485));
1708+
1709+
/* F81504/508/512 not support RTS delay before or after send */
1710+
rs485->flags &= SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND;
1711+
1712+
if (rs485->flags & SER_RS485_ENABLED) {
1713+
/* Enable RTS H/W control mode */
1714+
setting |= FINTEK_RTS_CONTROL_BY_HW;
1715+
1716+
if (rs485->flags & SER_RS485_RTS_ON_SEND) {
1717+
/* RTS driving high on TX */
1718+
setting &= ~FINTEK_RTS_INVERT;
1719+
} else {
1720+
/* RTS driving low on TX */
1721+
setting |= FINTEK_RTS_INVERT;
1722+
}
1723+
1724+
rs485->delay_rts_after_send = 0;
1725+
rs485->delay_rts_before_send = 0;
1726+
} else {
1727+
/* Disable RTS H/W control mode */
1728+
setting &= ~(FINTEK_RTS_CONTROL_BY_HW | FINTEK_RTS_INVERT);
1729+
}
1730+
1731+
pci_write_config_byte(pci_dev, 0x40 + 8 * *index + 7, setting);
1732+
port->rs485 = *rs485;
1733+
return 0;
1734+
}
1735+
16881736
static int pci_fintek_setup(struct serial_private *priv,
16891737
const struct pciserial_board *board,
16901738
struct uart_8250_port *port, int idx)
16911739
{
16921740
struct pci_dev *pdev = priv->dev;
1741+
u8 *data;
16931742
u8 config_base;
16941743
u16 iobase;
16951744

@@ -1702,6 +1751,15 @@ static int pci_fintek_setup(struct serial_private *priv,
17021751

17031752
port->port.iotype = UPIO_PORT;
17041753
port->port.iobase = iobase;
1754+
port->port.rs485_config = pci_fintek_rs485_config;
1755+
1756+
data = devm_kzalloc(&pdev->dev, sizeof(u8), GFP_KERNEL);
1757+
if (!data)
1758+
return -ENOMEM;
1759+
1760+
/* preserve index in PCI configuration space */
1761+
*data = idx;
1762+
port->port.private_data = data;
17051763

17061764
return 0;
17071765
}
@@ -1752,6 +1810,9 @@ static int pci_fintek_init(struct pci_dev *dev)
17521810
(u8)((iobase & 0xff00) >> 8));
17531811

17541812
pci_write_config_byte(dev, config_base + 0x06, dev->irq);
1813+
1814+
/* force init to RS232 Mode */
1815+
pci_write_config_byte(dev, config_base + 0x07, 0x01);
17551816
}
17561817

17571818
return max_port;

0 commit comments

Comments
 (0)