Re: [PATCH 3/4] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02. 10. 23, 3:57, Crescent CY Hsieh wrote:
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: Crescent CY Hsieh <crescentcy.hsieh@xxxxxxxx>
---
  drivers/tty/serial/8250/8250_pci.c | 39 +++++++++++++++++++++++++++++-
  1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index a70546ac361e..31bfe5381000 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1890,17 +1890,54 @@ pci_sunix_setup(struct serial_private *priv,
  #define MOXA_PUART_GPIO_EN	0x09
  #define MOXA_PUART_GPIO_OUT	0x0A
+#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_GPIO_SET_ALL_OUTPUT	0x0F
+static int pci_moxa_set_interface(struct pci_dev *dev,

can it be const?

+				  unsigned int port_idx,
+				  unsigned char mode)

u8

+{
+	unsigned long iobar_addr = pci_resource_start(dev, 2);

resource_size_t

+	unsigned long UIR_addr = iobar_addr + MOXA_UIR_OFFSET + (port_idx / 2);

resource_size_t. Why the parentheses?

+	unsigned char val, intf;

u8

+	val = inb(UIR_addr);
+
+	if (port_idx % 2) {
+		intf = mode << 4;
+		val &= 0x0F;
+	} else {
+		intf = mode;
+		val &= 0xF0;
+	}
+	val |= intf;

May be better:
  if (port_idx % 2) {
    val &= 0x0F;
    val |= mode << 4;
  } else {
    val &= 0xF0;
    val |= mode;
  }
(no need for intf)?


+	outb(val, UIR_addr);
+
+	return 0;
+}
+
  static int pci_moxa_init(struct pci_dev *dev)
  {
  	unsigned short device = dev->device;
  	unsigned long iobar_addr = pci_resource_start(dev, 2);
+	int i;

unsigned

  	int num_ports = (device & 0x00F0) >> 4;

And this one too (in the previous patch).

  	unsigned char val;
outb(MOXA_GPIO_SET_ALL_OUTPUT, iobar_addr + MOXA_PUART_GPIO_EN);
-
+	/*
+	 * For the device IDs of MOXA PCIe boards match the pattern 0x*3**,
+	 * the initial default serial interface mode should be set to RS422.
+	 */
+	if ((device & 0x0F00) == 0x0300) {
+		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 boot up.
  	 * This hardware buffer is only supported on Mini PCIe series.

--
js
suse labs




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux