From: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
Subject: [PATCH 3/4] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
Date: Mon, 2 Oct 2023 09:57:01 +0800 [thread overview]
Message-ID: <20231002015702.30509-4-crescentcy.hsieh@moxa.com> (raw)
In-Reply-To: <20231002015702.30509-1-crescentcy.hsieh@moxa.com>
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@moxa.com>
---
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,
+ unsigned int port_idx,
+ unsigned char mode)
+{
+ unsigned long iobar_addr = pci_resource_start(dev, 2);
+ unsigned long UIR_addr = iobar_addr + MOXA_UIR_OFFSET + (port_idx / 2);
+ unsigned char val, intf;
+
+ val = inb(UIR_addr);
+
+ if (port_idx % 2) {
+ intf = mode << 4;
+ val &= 0x0F;
+ } else {
+ intf = mode;
+ val &= 0xF0;
+ }
+ val |= 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;
int num_ports = (device & 0x00F0) >> 4;
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.
--
2.34.1
next prev parent reply other threads:[~2023-10-02 1:58 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-02 1:56 [PATCH 0/4] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Crescent CY Hsieh
2023-10-02 1:56 ` [PATCH 1/4] tty: serial: 8250: Cleanup MOXA configurations " Crescent CY Hsieh
2023-10-02 6:51 ` Jiri Slaby
2023-10-03 7:17 ` Crescent CY Hsieh
2023-10-03 7:30 ` Greg KH
2023-10-03 9:49 ` Jiri Slaby
2023-10-02 1:57 ` [PATCH 2/4] tty: serial: 8250: Add support for MOXA Mini PCIe boards Crescent CY Hsieh
2023-10-02 7:05 ` Jiri Slaby
2023-10-03 8:17 ` Crescent CY Hsieh
2023-10-02 1:57 ` Crescent CY Hsieh [this message]
2023-10-02 7:14 ` [PATCH 3/4] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Jiri Slaby
2023-10-03 8:22 ` Crescent CY Hsieh
2023-10-02 1:57 ` [PATCH 4/4] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485 Crescent CY Hsieh
2023-10-02 4:13 ` kernel test robot
2023-10-02 5:47 ` kernel test robot
2023-10-02 7:19 ` Jiri Slaby
2023-10-03 9:57 ` Crescent CY Hsieh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231002015702.30509-4-crescentcy.hsieh@moxa.com \
--to=crescentcy.hsieh@moxa.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®