Commit 43f012df authored by Crescent CY Hsieh's avatar Crescent CY Hsieh Committed by Greg Kroah-Hartman

tty: serial: 8250: Set RS422 interface by default to fix Moxa RS422/RS485 PCIe boards

MOXA PCIe RS422/RS485 boards will not function by default because of the
initial default serial interface of all MOXA PCIe boards is set to
RS232.

This patch fixes the problem above by setting the initial default serial
interface to RS422 for those MOXA RS422/RS485 PCIe boards.
Signed-off-by: default avatarCrescent CY Hsieh <crescentcy.hsieh@moxa.com>
Reviewed-by: default avatarJiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20231214060234.6147-1-crescentcy.hsieh@moxa.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a49a8b9d
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/serial_core.h> #include <linux/serial_core.h>
#include <linux/8250_pci.h> #include <linux/8250_pci.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/bitfield.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -1970,6 +1971,20 @@ pci_sunix_setup(struct serial_private *priv, ...@@ -1970,6 +1971,20 @@ pci_sunix_setup(struct serial_private *priv,
#define MOXA_GPIO_PIN2 BIT(2) #define MOXA_GPIO_PIN2 BIT(2)
#define MOXA_RS232 0x00
#define MOXA_RS422 0x01
#define MOXA_RS485_4W 0x0B
#define MOXA_RS485_2W 0x0F
#define MOXA_UIR_OFFSET 0x04
#define MOXA_EVEN_RS_MASK GENMASK(3, 0)
#define MOXA_ODD_RS_MASK GENMASK(7, 4)
enum {
MOXA_SUPP_RS232 = BIT(0),
MOXA_SUPP_RS422 = BIT(1),
MOXA_SUPP_RS485 = BIT(2),
};
static bool pci_moxa_is_mini_pcie(unsigned short device) static bool pci_moxa_is_mini_pcie(unsigned short device)
{ {
if (device == PCI_DEVICE_ID_MOXA_CP102N || if (device == PCI_DEVICE_ID_MOXA_CP102N ||
...@@ -1983,13 +1998,54 @@ static bool pci_moxa_is_mini_pcie(unsigned short device) ...@@ -1983,13 +1998,54 @@ static bool pci_moxa_is_mini_pcie(unsigned short device)
return false; return false;
} }
static unsigned int pci_moxa_supported_rs(struct pci_dev *dev)
{
switch (dev->device & 0x0F00) {
case 0x0000:
case 0x0600:
return MOXA_SUPP_RS232;
case 0x0100:
return MOXA_SUPP_RS232 | MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
case 0x0300:
return MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
}
return 0;
}
static int pci_moxa_set_interface(const struct pci_dev *dev,
unsigned int port_idx,
u8 mode)
{
resource_size_t iobar_addr = pci_resource_start(dev, 2);
resource_size_t UIR_addr = iobar_addr + MOXA_UIR_OFFSET + port_idx / 2;
u8 val;
val = inb(UIR_addr);
if (port_idx % 2) {
val &= ~MOXA_ODD_RS_MASK;
val |= FIELD_PREP(MOXA_ODD_RS_MASK, mode);
} else {
val &= ~MOXA_EVEN_RS_MASK;
val |= FIELD_PREP(MOXA_EVEN_RS_MASK, mode);
}
outb(val, UIR_addr);
return 0;
}
static int pci_moxa_init(struct pci_dev *dev) static int pci_moxa_init(struct pci_dev *dev)
{ {
unsigned short device = dev->device; unsigned short device = dev->device;
resource_size_t iobar_addr = pci_resource_start(dev, 2); resource_size_t iobar_addr = pci_resource_start(dev, 2);
unsigned int num_ports = (device & 0x00F0) >> 4; unsigned int num_ports = (device & 0x00F0) >> 4, i;
u8 val; u8 val;
if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) {
for (i = 0; i < num_ports; ++i)
pci_moxa_set_interface(dev, i, MOXA_RS422);
}
/* /*
* Enable hardware buffer to prevent break signal output when system boots up. * Enable hardware buffer to prevent break signal output when system boots up.
* This hardware buffer is only supported on Mini PCIe series. * This hardware buffer is only supported on Mini PCIe series.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment