Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2265693rdg; Sun, 15 Oct 2023 20:39:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGX5yUVMsWTG0Dquceb2jprfqbT2USEq3wELHsb98B9hm6UnxaGRwOCbYkFTjlxtkmOPs/F X-Received: by 2002:a17:90b:23d4:b0:27d:b3d:5c33 with SMTP id md20-20020a17090b23d400b0027d0b3d5c33mr14006396pjb.28.1697427597093; Sun, 15 Oct 2023 20:39:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697427597; cv=pass; d=google.com; s=arc-20160816; b=rjch2BdSwlS3ZpIdLCZwf6Zw3KDJG/mo8bHAbb3Z3JVRO2c3pFyV2oPOB7pxblZX+m jN/pIHMUPdAtG1E92d+Dqh7PNZ6RT2v3GUOI49se42xpLdXru2pLZnt8FLqrrWa6ggco ioEdRx6bY8Ib81nK72D/GGPrEpp+CcT7my6LrsJeM4xkMfII602a/aK+BdVaOgrIPPqZ hWWYXec8WiSlMzcIuJ0CSK3gyjIFjai80fRVzF3R7U5GZO8tpY+ZlQ3gZBd2Cprxw0iq HrQJ+mHmcf1joKEZpk7WA5giuktIqaiassEHHvi6iFWRBqkzHdpKqI3N/PzKK/ibaPyH RNiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=s2yAgbspSMTms9Mv2QJDXvt3gZLQAkOVTBeqqFiwZf4=; fh=dWbthtzWZNNv/qBjgIYPy5/MGf04SzuWGbYFod9k0XM=; b=xg/MhTdQy6n8+KB4YdBn65g6s72+xGEWHalc3Rbb0iIgxbZJr2Zff6NkipwKopEq85 Ls2LE2S0rWhi+oxZWb4UtWeSDZ+fceOa+iY9U0ZZ8ASzqJfTTdoOivypjC7YxkGhKFpW aD4W81TOfPF8KrdCjpfoRYBwTw+Dkq2SZL8OP0jn5IBSTXB/nlkm2MaWmEDplZnfK4Y8 kX4AUZpYB7L+gsPgQXD8271aYi7UDRzeHYT5KsbbemAW6f6YK6knhOlwdB0jedlaRTCT b9mod/6SUVDdn8XLA7AwuzlOcXiSRjHB3lxKicmkdopHzh9D1EaLoMuHHIl3N3mTASYj LXog== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@moxa.com header.s=selector1 header.b=DqfBZxFr; arc=pass (i=1 spf=pass spfdomain=moxa.com dkim=pass dkdomain=moxa.com dmarc=pass fromdomain=moxa.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=moxa.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id i16-20020a17090332d000b001bc8a9f5e52si10630791plr.135.2023.10.15.20.39.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 20:39:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@moxa.com header.s=selector1 header.b=DqfBZxFr; arc=pass (i=1 spf=pass spfdomain=moxa.com dkim=pass dkdomain=moxa.com dmarc=pass fromdomain=moxa.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=moxa.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id A244E8096A41; Sun, 15 Oct 2023 20:39:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbjJPDjn (ORCPT + 99 others); Sun, 15 Oct 2023 23:39:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231550AbjJPDjW (ORCPT ); Sun, 15 Oct 2023 23:39:22 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2059.outbound.protection.outlook.com [40.107.117.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D4E5DE; Sun, 15 Oct 2023 20:39:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ck4llEgPDb2fAXfZXetrwo7g2H/4P3yAgNOBi+Pu28MSR1/NE5m7yVbhWif9rBAZj9PC8OID20Nzwtw+EhlR6E9G7sEni7raqbWy7kp+iY88Kj0FdEm6APzTQmK0Oh4GPVCaGfwJlfhiB77in6GNEgs0KrCoIQEmFY9ZZzlK/jvRPPXqAtzzfktZrhRXOmlFF1ZkzQG39CF8XttfuHvzj2iFsse9zVX9bIX+N8fqxYDxLF0GgaNi53UClR8LNQy+dmN24lBKeMfYWuZodcIHD7XPzGtxbPdObwx61KJlkyCls4FeF/DaCFwblmsgOgyzQqnaaQy6Stdc04RJ5hWPPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s2yAgbspSMTms9Mv2QJDXvt3gZLQAkOVTBeqqFiwZf4=; b=mklYt5sE74wTYBub9rC/IbMGn469vgAOF6/1Hl92Vni2xOT/D1s1gxpoRDdhldMEencjY9i4AcOcrBxDSDpV4LNxnSj9d0UYs5G+byCIlj6E6N4SYe8MymONrSeu8O7SMdVjWFAOqVsqgYlJrMwZfea3XHdCZLZnq6KGPKlMTPkmJbxWixWdoOT3tq2Ok9lwzK9/CNbkA2Ei6x1PYkUuhO/TpL74A9+UsR8RYAokjDRo53oB/wWEQI7DdZ5IH90/+T2HivGYuotEpPhd1R1Ya3bQpNVwW0N4LTMAEoU3LzjPXlCvnfyFboSEG5kdw/1itLA5ClhTahxDsPvPJvIiRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=moxa.com; dmarc=pass action=none header.from=moxa.com; dkim=pass header.d=moxa.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxa.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s2yAgbspSMTms9Mv2QJDXvt3gZLQAkOVTBeqqFiwZf4=; b=DqfBZxFrxGRSGZM/U+3BbASe6IEhHfvNx5z5S1JCYAbtH9i6N79lH+TnIxXODO/Y/BN4EmlLMbneEFoWIW+WlOqWSalunG2bRzQrAP4t5/70oFdJdeCAIJvyQYifUIIlJIWa4Q4GoqDJTpmetuPzYtO5pr5dzP1oL6zHRPscWCM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=moxa.com; Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) by KL1PR01MB5156.apcprd01.prod.exchangelabs.com (2603:1096:820:d6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.34; Mon, 16 Oct 2023 03:39:17 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::3f1:6c0e:dec3:714b]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::3f1:6c0e:dec3:714b%5]) with mapi id 15.20.6886.034; Mon, 16 Oct 2023 03:39:17 +0000 From: Crescent CY Hsieh To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Crescent CY Hsieh Subject: [Patch v2 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Date: Mon, 16 Oct 2023 11:37:04 +0800 Message-Id: <20231016033705.20669-6-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016033705.20669-1-crescentcy.hsieh@moxa.com> References: <20231016033705.20669-1-crescentcy.hsieh@moxa.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TY2PR01CA0015.jpnprd01.prod.outlook.com (2603:1096:404:a::27) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|KL1PR01MB5156:EE_ X-MS-Office365-Filtering-Correlation-Id: efac9867-75d4-4656-aff5-08dbcdf97997 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1SsmC1sQLuMyNBbaYgK5qIddgbDdsd/Bif3N+tlwiTllv8XRaVKWMzDWv+NgzkKBWqt3Ang4ShhgYJ9kWzsTh6kbY1Nt92o2ha7W0Y4AV0GzR8+ZlA/guhLQnYW+pGc9owXMqkE+9OFES0flWHSOn2+/wWg/B+Q8WFYxirP4d+MBe0duiPBgAIDyKCFvbfzQX1XzMdkH9i0DYYO8zr1MoNvKIMC/5+en0XHFRr83tITD0bcNqxbw0JE2stF8amt+0mBIxSUymufBpK53DQpozpbuz5r4rCzPKsA9mUifoFXGxSDMrqjSxONttrxOJNGHp5R/WYRC1oyJEfDYU/jT0EzwQIA9pjTJVXh8qpkRqeJzI5ogLp1EJDBoQh+4+aYtZk8+ZE2ji60v/MYQx9xPZ2gLgnVmTGD6uuWvaKAaq62U8YX54wJ8YCKnedwEiaB6BfCgON51KvoLi61AfaClhDQJwUd/jCLeZlEHLqudWgL1Q9ab6HYZUBFtm0FVSFpwstIynpaDs9n/MTwSvXrA3HDSXljE+wI79yfqFUP5WXTzRDe+UYYpW2Qv+ulz63cYZMkKK3Fvrw0VDVuwz/n3v2o2wUPihqj0o+VpGYk8xS7y7CCPR85Tz+tw/AdlPmqV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR01MB5405.apcprd01.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(39850400004)(366004)(376002)(136003)(230922051799003)(186009)(1800799009)(64100799003)(451199024)(6506007)(1076003)(26005)(107886003)(2616005)(38100700002)(316002)(52116002)(66946007)(66476007)(66556008)(6486002)(478600001)(6512007)(6666004)(38350700005)(4326008)(8936002)(8676002)(5660300002)(2906002)(41300700001)(36756003)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?fkSCQ5CGktpz3xNzpd4dEu5DtHr3xEkLzHxqg6mLj9MLJSiPC9rvBprLYM1W?= =?us-ascii?Q?kwTI5cC4/9vcI6RmaOduYEIzwDoTeF6c1RxI3oTuwaM4FKuXoJXAR079rwiQ?= =?us-ascii?Q?6u+fF1m1h7wSF3nKHedCpXzH07V1A0t/V/93nrExoY9l4T/ntgKTJDFwpB8y?= =?us-ascii?Q?G9JIgZkVRgg2jQOotuCbYJxIePMRxC+GJ6NH4mOR1N7TsplfAxa1VIQVGa7+?= =?us-ascii?Q?IHyZtwY7ShfM3ZDFObRfDegtKNqql9w8DyfUzmUdh5nXTZ6eN84jvmHr+SYG?= =?us-ascii?Q?Nf62gLCQxlWqh+FQ3VkVNH2bWaf8S9mbsRy3HG1aQRqV3aFlpH1fOG7OV0/V?= =?us-ascii?Q?xFvWIJic5Y5CA5lByb6dcQVlI5YyBXwMp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Iy?= =?us-ascii?Q?6brA9gmJGdbyVuQ7PCOygwvNyVtj0OM7qrkI3dzEeVuuN0NntOok0xNXXP76?= =?us-ascii?Q?URXlRzK1tFsitjx/iykRBkIPfZVC+2RMN6VUhd5cQ1iDNif7H5gUpzV60KsF?= =?us-ascii?Q?Q6XmD80Lvsddj2sVeLXsMB+I3dhmHeJxAPRGs5bmS9rbyNIjijGu06qnVqfb?= =?us-ascii?Q?9wElfMICcL7KdB5KQV0ILXOjRhUYnzs4w8AN7WNg1nWENmb6Jk+bIvWfDWmh?= =?us-ascii?Q?Xx3Pwsn2yWpSkL6KIUHivGHoi81VU8NmTUXeSAH7kYkpQL4ylzzIEqit/z1W?= =?us-ascii?Q?9/pYnBJMqXOTetOHQRDweslZvcbAYG7Ue1cQOD2Bwh1W2C7LySA4fzf6FA1g?= =?us-ascii?Q?BQ=3D=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: efac9867-75d4-4656-aff5-08dbcdf97997 X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 03:39:17.4991 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5571c7d4-286b-47f6-9dd5-0aa688773c8e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Hm2mx5qAlvzCvJnNR++Uw927cymPT1EOQBytZ4jNX1pV+48PRolM0p+GNXprrir0kTIXIVLh6M8fQVDvx3x+fxFghhKa/dRUhBMyAEMj/vI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR01MB5156 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 fry.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 (fry.vger.email [0.0.0.0]); Sun, 15 Oct 2023 20:39:54 -0700 (PDT) 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 --- drivers/tty/serial/8250/8250_pci.c | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c index d22f727491b5..72dd27141801 100644 --- a/drivers/tty/serial/8250/8250_pci.c +++ b/drivers/tty/serial/8250/8250_pci.c @@ -1970,6 +1970,12 @@ pci_sunix_setup(struct serial_private *priv, #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 + static bool pci_moxa_is_mini_pcie(unsigned short device) { if (device == PCI_DEVICE_ID_MOXA_CP102N || @@ -1983,13 +1989,49 @@ static bool pci_moxa_is_mini_pcie(unsigned short device) return false; } +static bool pci_moxa_match_x3xx(unsigned short device) +{ + return (device & 0x0F00) == 0x0300; +} + +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 &= 0x0F; + val |= mode << 4; + } else { + val &= 0xF0; + val |= mode; + } + outb(val, UIR_addr); + + return 0; +} + static int pci_moxa_init(struct pci_dev *dev) { unsigned short device = dev->device; resource_size_t iobar_addr = pci_resource_start(dev, 2); + unsigned int i; unsigned int num_ports = (device & 0x00F0) >> 4; u8 val; + /* + * 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 (pci_moxa_match_x3xx(device)) { + 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. * This hardware buffer is only supported on Mini PCIe series. -- 2.34.1