Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp153498rdb; Wed, 18 Oct 2023 23:25:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5GlqhrgLf3qYNSp2sFsH3orjeDdsOp4oq4nWlJoyfJNqouTli5vJgOBRnnTtwdKrKeGwc X-Received: by 2002:a05:6358:1802:b0:166:e2f7:2e43 with SMTP id u2-20020a056358180200b00166e2f72e43mr1099017rwm.10.1697696711246; Wed, 18 Oct 2023 23:25:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697696711; cv=none; d=google.com; s=arc-20160816; b=OpATEkyZR+2z3qlY1t0z+z/6FLruLJQDWrzkI0TmHEnOOifQPvbabg/Y3yweX0Kv+E lOmm+eFWKkLawZHndMMVToZC+TIZIXXj4KmdgFMbfg/30TLL1m++xnLn86dCEIBMJLHV 3wwwIu5tNoy/c9KQcswbdGHb6OeutD/7R8p6PSHZi2WfbKs0Tp/gCIYABgFW/YcwYv9x JiPfSAOuWzKb3xRWNlgDrMYIDPOsglymuFIioBh0pgGUA7lw68nKSpKfC3f7Rn1V7UPO t6+vaWVzXwAxAIO8gHYeqCl0RB+t0AKjoTum7JPLno/zG7qyk9AK+YbFtxpxJOHl0oLN GV0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id; bh=Z8PRDTflJ4UXV9ZO5LwnSfS1FDe1mCJ5OgI2BICQvko=; fh=Dohtn8zJcMCIEnkl+6aNEtJyXLcnoEqLwY28K3Wa0As=; b=Rqg0ywyaU8vLUhGCaziNS8KYtnSPPYGOh+nLjbxAPcfYRIwBbvo9EJd1wLCNnposEv 4XuACMcQ4XVgtLUpclwSYl3yRcOimkkFZrE7UFNcfDijgl47IKFhygp0JK6b21Br/1nP ZbWTpgtsUCZYRLEFqtKILvN176mGpKojlCMPUZuJKHVZTFl+gKDmiJ1Eapoy+4ye3xnG UIk70VnQpT3CHncMwwHAYKqy08gTM46DWAh74N84IlzEVbVvmOqJbTxgExqx6C/Z20iV sRFUuJYUSh2GHANKJLVymOcUfuBVJDW09n2RKeYfHw9n0pKcGLtzkk1yPHbDSgw25Luy tRUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id be3-20020a656e43000000b005b7d939c3d9si3832116pgb.651.2023.10.18.23.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 23:25:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id F2574822B70E; Wed, 18 Oct 2023 23:25:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232583AbjJSGY6 (ORCPT + 99 others); Thu, 19 Oct 2023 02:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbjJSGY5 (ORCPT ); Thu, 19 Oct 2023 02:24:57 -0400 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28FE1BE; Wed, 18 Oct 2023 23:24:55 -0700 (PDT) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40651a726acso66250085e9.1; Wed, 18 Oct 2023 23:24:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697696693; x=1698301493; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Z8PRDTflJ4UXV9ZO5LwnSfS1FDe1mCJ5OgI2BICQvko=; b=qm38wYePl6hsJri1oz8yAPZcz9xDaJ1MCWp8glycoCCxM6ygbEmZWQykruGnEXuyYF x/OSjoeZyLp5+3qhqlCqR9nF7wPxaJZX2DLTkxRpZp0BbuAhX+KSDRjue+Yl9AEqpaH1 VaeBeuchvNfxakkfEpepQQe60+w5kx/bYrPNDWpDst9ws6Z+5WFZSKp9gJcR1esDu5Yc XFLDpGwVU98hBuxRJ9o1KGiqtsPX7e1ouRX1QgRBWOKgns0LLtrdIaimR5mLOkQNZa3x iyUlQtcjJ5IJ6r/TuY4ddQnHzpeHj/E3HeLyYA14u7ABddDjZ14/4PA6Bs/NZwDGaLEM imcQ== X-Gm-Message-State: AOJu0YwMbsLfoNtzBABYsJSwGFrU4YNQZWrxwq1O1IV1W/DHF4HzyxYK jLlG96DQyyM1I+EVmV2Q9xrJw2DuNvU= X-Received: by 2002:a05:6000:1112:b0:32d:8958:c570 with SMTP id z18-20020a056000111200b0032d8958c570mr780548wrw.29.1697696693434; Wed, 18 Oct 2023 23:24:53 -0700 (PDT) Received: from ?IPV6:2a0b:e7c0:0:107::aaaa:59? ([2a0b:e7c0:0:107::aaaa:59]) by smtp.gmail.com with ESMTPSA id g15-20020adfe40f000000b0032d88e370basm3711853wrm.34.2023.10.18.23.24.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Oct 2023 23:24:53 -0700 (PDT) Message-ID: <59728ca9-cf2b-452d-b24c-1ee1e31a1f04@kernel.org> Date: Thu, 19 Oct 2023 08:24:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485 Content-Language: en-US To: Crescent CY Hsieh , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org References: <20231018091739.10125-1-crescentcy.hsieh@moxa.com> <20231018091739.10125-7-crescentcy.hsieh@moxa.com> From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVLEkSVz6FoqCHrUTx wr+aw6qqQVgvT/McQtsI0S66uIkQjzPUrgAEtWUv76rM4ekqL9stHyvTGw0Fjsualwb0Gwdx ReTZzMgheAyoy/umIOKrSEpWouVoBt5FFSZUyjuDdlPPYyPav+hpI6ggmCTld3u2hyiHji2H cDpcLM2LMhlHBipu80s9anNeZhCANDhbC5E+NZmuwgzHBcan8WC7xsPXPaiZSIm7TKaVoOcL 9tE5aN3jQmIlrT7ZUX52Ff/hSdx/JKDP3YMNtt4B0cH6ejIjtqTd+Ge8sSttsnNM0CQUkXps w98jwz+Lxw/bKMr3NSnnFpUZaxwji3BC9vYyxKMAwNelBCHEgS/OAa3EJoTfuYOK6wT6nadm YqYjwYbZE5V/SwzMbpWu7Jw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yzqzffzBLXZCujlYQ DFXpyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: <20231018091739.10125-7-crescentcy.hsieh@moxa.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 23:25:09 -0700 (PDT) On 18. 10. 23, 11:17, Crescent CY Hsieh wrote: > MOXA PCIe boards have 4 serial interfaces and don't require additional > stuff to switch between interfaces: > > - RS232 > - RS422 > - RS485_2W (half-duplex) > - RS485_4W (full-duplex) > > By using ioctl command "TIOCRS485", it can switch between default > interface and RS485 if supported. > > That means, for RS422/RS485 board, it can switch between RS422 and > RS485 by setting the flags within struct serial_rs485. > > However, for the RS232/RS422/RS485 board, it can only switch between > RS232 and RS485, there's no flag for switching interface into RS422. > > This patch uses "SER_RS485_TERMINATE_BUS" to represent RS422 as a > workaround solution: > > - RS232 = (no flags are set) > - RS422 = SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS > - RS485_2W (half-duplex) = SER_RS485_ENABLED > - RS485_4W (full-duplex) = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX > > Signed-off-by: Crescent CY Hsieh > --- > drivers/tty/serial/8250/8250_pci.c | 58 ++++++++++++++++++++++++++++++ > 1 file changed, 58 insertions(+) > > diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c > index 29a28e72b..098ac466b 100644 > --- a/drivers/tty/serial/8250/8250_pci.c > +++ b/drivers/tty/serial/8250/8250_pci.c > @@ -1974,6 +1974,10 @@ pci_sunix_setup(struct serial_private *priv, > #define MOXA_RS485_2W 0x0F > #define MOXA_UIR_OFFSET 0x04 > > +static const struct serial_rs485 pci_moxa_rs485_supported = { > + .flags = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX | SER_RS485_TERMINATE_BUS, > +}; > + > static bool pci_moxa_is_mini_pcie(unsigned short device) > { > if (device == PCI_DEVICE_ID_MOXA_CP102N || > @@ -2024,6 +2028,46 @@ static int pci_moxa_set_interface(const struct pci_dev *dev, > return 0; > } > > +/* > + * MOXA PCIe boards support switching the serial interface using the ioctl > + * command "TIOCSRS485", but there is currently no dedicated flag for switching > + * to RS422. As a workaround, we utilize the "SER_RS485_TERMINATE_BUS" flag to > + * represent RS422. > + * > + * RS232 = (no flags are set) > + * RS422 = SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS > + * RS485_2W (half-duplex) = SER_RS485_ENABLED > + * RS485_4W (full-duplex) = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX > + */ > +static int pci_moxa_rs485_config(struct uart_port *port, > + struct ktermios *termios, > + struct serial_rs485 *rs485) > +{ > + struct pci_dev *dev = to_pci_dev(port->dev); > + unsigned short device = dev->device; > + u8 mode = MOXA_RS232; > + > + if (rs485->flags & SER_RS485_ENABLED) { > + if (rs485->flags & SER_RS485_TERMINATE_BUS) { > + mode = MOXA_RS422; > + } else { > + if (rs485->flags & SER_RS485_RX_DURING_TX) > + mode = MOXA_RS485_4W; > + else > + mode = MOXA_RS485_2W; > + } > + } else { > + /* > + * RS232 is not supported for MOXA PCIe boards with device IDs > + * matching the pattern 0x*3**. > + */ > + if (pci_moxa_match_second_digit(device, 0x0300)) The same here: if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) > + return -EOPNOTSUPP; > + } > + > + return pci_moxa_set_interface(dev, port->port_id, mode); > +} > + > static int pci_moxa_init(struct pci_dev *dev) > { > unsigned short device = dev->device; > @@ -2063,9 +2107,23 @@ pci_moxa_setup(struct serial_private *priv, > const struct pciserial_board *board, > struct uart_8250_port *port, int idx) > { > + struct pci_dev *dev = priv->dev; > + unsigned short device = dev->device; > unsigned int bar = FL_GET_BASE(board->flags); > int offset; > > + /* > + * For the device IDs of MOXA PCIe boards match the pattern 0x*1** and 0x*3**, > + * these boards support switching interface between RS422/RS485 using TIOCSRS485. > + */ > + if (pci_moxa_match_second_digit(device, 0x0100) || > + pci_moxa_match_second_digit(device, 0x0300)) { if (pci_moxa_supported_rs(dev) & (MOXA_SUPP_RS422 | MOXA_SUPP_RS485) == MOXA_SUPP_RS422 | MOXA_SUPP_RS485) or maybe even simple: if (pci_moxa_supported_rs(dev) & MOXA_SUPP_RS485) ? > + port->port.rs485_config = pci_moxa_rs485_config; > + port->port.rs485_supported = pci_moxa_rs485_supported; > + > + if (pci_moxa_match_second_digit(device, 0x0300)) if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) > + port->port.rs485.flags |= SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS; > + } > if (board->num_ports == 4 && idx == 3) > offset = 7 * board->uart_offset; > else -- js suse labs