Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp857912rdb; Thu, 30 Nov 2023 23:41:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKdwas3lhcNdzyKdUmgERJsPmUzKel5MSxw0Lt5bU68SWWMnmxg9mJ811PgbVi9rCE9eSg X-Received: by 2002:a17:903:234c:b0:1d0:5ac4:2940 with SMTP id c12-20020a170903234c00b001d05ac42940mr567795plh.9.1701416481181; Thu, 30 Nov 2023 23:41:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701416481; cv=pass; d=google.com; s=arc-20160816; b=Vni3sqv87sccCoqv6ockIqQ1JVzpMg9eNAlP1+a02O0qOwNL7dslpA8l355F7Qp8W2 tryzIYbNxHmHXMqDPFhdKRW6FMVtYzMBk/+V+UBW+uGHucxCIS0rIb8C8USXd0hztzII 3ERlbcr0dls1/N0VepJK0FHExKDtM0o89MGq1hNSzobTJ2d40SMqbGTRQkTe00u956em b3bT283C0PeXtWgYq9kSjLzSQEA/MGQu1d/p440JuiPgJ7B9APZeSItEBEKGM+6VNpm8 RTbD6DuNYoNnZjsLB7VOXHJZrJ/fLu3Ma5PlXpES3FRaSv+kvyhsdISYiUUqVh/GZBvy 3yrA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=V5C9lgpJnMN8K9fCXg/F/q0bjyuXeXT4SOfMDaTjRgs=; fh=9IbzxucUBWcgEvhe+WtoxtT+FpcGkFAf3REsKls7q2A=; b=XRqACJDHjz0rV8A+/1OI6fTfPu9sccawnIPovnuSK92TJgC1HBm+TVL23YlHC5slRQ 1mFw6+ct3fV+ubTYvtJr+gVMfTt6jY34PZaFndsscW9UU5ov3K4bmwtMWy9xk5PfExC4 pxjtiRTry2bwODkZbU5+FdiD6eINHTcukhq7+zS9Sc1zM8ZPoYf6ezfwjbdwhoyFNagi MoMqtbyytDxa+6822eG7FBw8jQ4LDI+wfsR2fJu19iuhyeGJZOnrT4kytizJXEMWaRVn AAJu4nm5EIUq/KKFU867hXW40YGzyno+3EjXqsJNMa/lnSU/iqiHJeOI43w2DC8Inlbh KcDg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@moxa.com header.s=selector1 header.b=ASYBC4Am; 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 23.128.96.38 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. [23.128.96.38]) by mx.google.com with ESMTPS id u4-20020a634704000000b005c1b5a76098si2760962pga.771.2023.11.30.23.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 23:41:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@moxa.com header.s=selector1 header.b=ASYBC4Am; 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 23.128.96.38 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 A8F9D810678B; Thu, 30 Nov 2023 23:41:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377746AbjLAHlE (ORCPT + 99 others); Fri, 1 Dec 2023 02:41:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377734AbjLAHlC (ORCPT ); Fri, 1 Dec 2023 02:41:02 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2070.outbound.protection.outlook.com [40.107.215.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CA131719; Thu, 30 Nov 2023 23:41:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N/CG6nBMxLFP8+JHXrMuBKu9wRG7YgyF2xrgNVQYToVqcLErar19aiynLHwMaxpF29FE+JbqakRBRpNCfbJfvNI8r76sbmU+qWM6es4I5iHsMMv6uOJHL8/riHylB2x+aw2JZh8JPa+YJW/JgWXhZ8W6Nd6xDX5Ny7dixoZianYBmN3tQkS8Y4Lo/R5k6EOFcksJmrgNpTVljaBtrR3cHc5sQDo+nJZg5vUIjUafRGqNjB1f9YclBjsp52/JgCSgeSQjE+pcxQ9MRpwWiW4mO4P2rj7Svly17gfDi7hG//LDnJrfSFLYqtzLdAAuer5PcIy7UG+TeNNWvWygfTCFiQ== 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=V5C9lgpJnMN8K9fCXg/F/q0bjyuXeXT4SOfMDaTjRgs=; b=Wkxi3HdIIg5v3UNKRurhl42eybN2dltRpTMaE2jDd/8LH/pasHqmULEfd+uSrNIQdk6cWbhsgAAF5/uL8bQRZWRlXMRTTH/8z99renWLjdBwvSdG3t9Q0IYKlMt2VdccRYobAYOOlJ65AKBqeLoooddLX487pYJKmoIfcActIf1U/msOpxBZQfbpYbF3y1pPbuil/itwEomX/E12NbVD2aUq6J/gJUptD9vfO4+q387Oj8qD2oksRKzAuobRJkCrZkxRpYnucxtgCO/cCtxXjkqg/IyJhuYSrocm1wAC4ktrdwCYDewoZvwikd4REAo832keOh8oj8K5VlQKaYg8DQ== 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=V5C9lgpJnMN8K9fCXg/F/q0bjyuXeXT4SOfMDaTjRgs=; b=ASYBC4AmV9SfJFDddFsJXgfnyZAl+4BlHG1DwbzsH3D/lBfeHMSv9EZRskF4BwtIPl1tb2T+UWnB2TXsW6qFj6ESsetZOi4veDBGvDKztWw7sddMdL3WPQmk23TaTmj4kDKPe4n+6a7aNfOB1sN7FlbT6xg+hZ+opSsIC67L6dg= 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 SI6PR01MB6633.apcprd01.prod.exchangelabs.com (2603:1096:4:243::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.26; Fri, 1 Dec 2023 07:41:04 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::1023:2132:c05e:ea6b]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::1023:2132:c05e:ea6b%2]) with mapi id 15.20.7046.015; Fri, 1 Dec 2023 07:41:04 +0000 From: Crescent CY Hsieh To: Greg Kroah-Hartman , Jiri Slaby Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Crescent CY Hsieh Subject: [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Date: Fri, 1 Dec 2023 15:40:55 +0800 Message-Id: <20231201074055.259207-1-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TYCP286CA0282.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3c9::9) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|SI6PR01MB6633:EE_ X-MS-Office365-Filtering-Correlation-Id: 905329d0-6870-4071-3e7d-08dbf240df24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9B9dEfMSTX4yL810E3JZFLqe4giorzEPxoTIDmJY7rB/wgb0ABMyC3zZeXVCTZQZxXDjH7Lt+BZxWDefK/Jka/FjP0jsKMbqhRO74ADBzaoONg5+CN68TBFeJTs59cffIa8bdJI8PCXHjDoYdn7kcRekSQokPZuRAMzxx9U4TwCtsf96gpi4wj5X56sJGNDYkhprPZE0My3b7RkFaBXCZdrKtXr0Xceo9gWkOLxZDuOlwJh/lc66xenHVNPMQnISAfaOSehc1BbypwoCm9hsjP0ufzpvtbu2LTwRfWUCDqYLBt0rJ680ec/J30EZNJJq6kjiJr6QBBkgraMKUs3azoZsHOAJAArxd3Iunu9sfmg0g7iRHnnkbsX5FLaPMkyYuDfxLEgTcFYRydSTe3RYbTrdnIxK3lRv55fCuG86hzrjEa78PW7QGi1l8VuGCStnVdd7gY4ZxHHLLe4PS85oy1mJXNT4M90VepwKA8rUgLvbuBTuFP7XR8v5G1J7G78ctWEZK61KSxCf/5RwfiWFK/Mqs7CMJjeCK1CG0yyhhM5ilZlNpYkJ4ylEKyQ7SVf+iyivKCRc9nfa3OANepzEG1LNtRegLj9dFEBJFMlfvEvmP0i9UCY9XCnJjDxqD4jl 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)(39850400004)(376002)(396003)(136003)(366004)(346002)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(107886003)(6666004)(6512007)(2616005)(26005)(1076003)(41300700001)(52116002)(83380400001)(478600001)(110136005)(6506007)(6486002)(8676002)(316002)(4326008)(66476007)(66946007)(8936002)(66556008)(38100700002)(86362001)(36756003)(2906002)(5660300002)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?LjW0fyv1xQqhnGfeRNzNURfXyhBsWEDpHJI0febtiwt/6+ez/uIfoz4XaoCO?= =?us-ascii?Q?guaNe9k7qVfghIHJCqMCe7lT95eh3l79IMfGtGDUz989PS6GHGb4S8OJKto0?= =?us-ascii?Q?i+v0ZlFRLAJhJ1Et5VTd02mwJeQ0taud9jCcudemSzSMILKxZaYnPfwrR5U8?= =?us-ascii?Q?b9v1QgFC9ywVtwCJBaoyBOhArx2jJeqbXf89+YwEit6HZ2qWCUHBjfUTIG1m?= =?us-ascii?Q?Li0IY53O1ujOXCG2Qg8OmoizLKdFc7GaRUV1hVuhdJJ7nN08GikvLfXNf+2Z?= =?us-ascii?Q?jVabuTd1l3UtMNQ9EJBfvUH5cm539zz0ilHKaoAnRvJOvvGXUf8tGvJL8Qem?= =?us-ascii?Q?1Jk+u9CaECk02P1t/xulN/XifrTa3HPqpKPCyT0iV6YDtWQrC+/Yh+NnIQhY?= =?us-ascii?Q?44Xv4BDicv5pdof2OTpPkyELYlLzJAwYxYliVWMJ+ogrmqjUj4udIfoO0FWV?= =?us-ascii?Q?pQdK43dz0lyddzb5V8SsU/+3cz5RjIZTtdBjnVmazIg+1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5aS65yD6kMBvwiWo0bH8L2b9K5K9hH3+c0bc7Svrg72+7qASWeOm?= =?us-ascii?Q?yJLotR/ybqrWNCxzyHBng6kK8rxubHlvPBZRqMHovN3UaTXsUJZHGCD/u67m?= =?us-ascii?Q?q92Hc9L86D7oH80vCQQjg8t7q9wAWLQCLeycAkqyJVYezbGKx+2KLCBhYLrB?= =?us-ascii?Q?gPZK/gGIZQjobRpJDsf4zIX4PXaJB0pL41xoDkKFy6Y7NC0d40c3UY2owjaH?= =?us-ascii?Q?oA=3D=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: 905329d0-6870-4071-3e7d-08dbf240df24 X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2023 07:41:04.0284 (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: 4UUzUFREZgQ7ftpW8+mSSv93SGv4dqBRBFvBapc+5ZW5fOYUIru59lAjl8OTj+wS1izqmryJDj1n4MKbt4B7C1zBLpYFQvwIMLhHauN4wx4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI6PR01MB6633 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Thu, 30 Nov 2023 23:41:18 -0800 (PST) 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 Reviewed-by: Jiri Slaby --- drivers/tty/serial/8250/8250_pci.c | 58 +++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c index b2be3783f..66a2450da 100644 --- a/drivers/tty/serial/8250/8250_pci.c +++ b/drivers/tty/serial/8250/8250_pci.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1968,6 +1969,20 @@ 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 +#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) { if (device == PCI_DEVICE_ID_MOXA_CP102N || @@ -1981,13 +1996,54 @@ static bool pci_moxa_is_mini_pcie(unsigned short device) return false; } +u32 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) { unsigned short device = dev->device; 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; + 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. * This hardware buffer is only supported on Mini PCIe series. -- 2.34.1