Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp947980rdh; Thu, 26 Oct 2023 23:26:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1zCYKj+bntqfZbiehb8VM09sOPjIjSLRRCT/+x0OeJbvPVIf08iCtL1S1Z5FlGKjGGsj6 X-Received: by 2002:a81:ac55:0:b0:5a7:d368:bf88 with SMTP id z21-20020a81ac55000000b005a7d368bf88mr1764726ywj.2.1698387999814; Thu, 26 Oct 2023 23:26:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698387999; cv=pass; d=google.com; s=arc-20160816; b=Mmy7QfiuyIxK3dW4T9bGOlAKquvFuFiv7nU6vChia65QdkDvinTbf8JzRpvmg6xrsZ qrc5OPvftD/B53eIoHOQ+J88fx1u/PHX5kEtNBrOeUiWo0OWD6PrQhjFS5zAb2drYjWq bxY1ffcH9oVLAQf3uWDJ88LuFwzhs+DjMVjRYoJUUkoCYfB29ATc8jlT11hQa/MiGkEw 6STTjhI1zKp9AHWXn83vnVZoNe7h+LKhWCBIYcDPYoLHVej+hP47nNT66SS+7qm5ju7r bIORZNcljz0EK0NOFEAUl1VF9yKsITtESGBW6IsUZDtZlCzEfVCqOMvwhhtDXb+10bUX YWig== 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=y9l1w2+8VjOrBlskqMt7yo18vaGBhUWmQAJn+1ysJ1c=; fh=9IbzxucUBWcgEvhe+WtoxtT+FpcGkFAf3REsKls7q2A=; b=mJRDfdg1eoFJF0N3Z+37N6m4YT4FNIKyUTPm2CfuHZh09A5FZN0UT3tUyTBsWVI/7T JwWpdtvH10nmC7HXbZydP7D9oNlQu65a/EBFU38InNB1wReEVHrpPxLJqWk0rXEiBBrc BrliY88j8WTPivSnFELgtHKWN2NIIYmb9MUgEWYj8Nlon3Vr16eE0NIfMaW+KtUjgyp3 xuCqmCxAQT8OHUdXLkXB9RW790pCpf7g2+abDCF23Bzm3rJNiM/xtEdaW+VkQFfowhRm tl0oVWGLO+l5EDhYoAF+7gpb7GDnIu9OPmVI3PNriCpCqQeK6fT6n/863Z6sraoFyoYE RJvQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@moxa.com header.s=selector1 header.b=K38rieJd; 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:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id g13-20020a81fd0d000000b005a247e9283csi1593316ywn.257.2023.10.26.23.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 23:26:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@moxa.com header.s=selector1 header.b=K38rieJd; 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:4 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 howler.vger.email (Postfix) with ESMTP id D61688023B91; Thu, 26 Oct 2023 23:26:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345189AbjJ0G0E (ORCPT + 99 others); Fri, 27 Oct 2023 02:26:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbjJ0G0B (ORCPT ); Fri, 27 Oct 2023 02:26:01 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2047.outbound.protection.outlook.com [40.107.255.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7A961B2; Thu, 26 Oct 2023 23:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Chay0qxpPCstQftwvA75S6brTGR4tCOMlEDzlHeI9e5tSl1tWkh2U5eLJT9q5lP//6Lk+iJn/gVVfSz8ziTAalEHmGNrd7SJG4MaZibY0uCJs/K8CqPzMSxcn8KMHZrK6Wl2L+Bf/ymwDKwrxDEhtiU7vpC+6qPRCwUjrnU/UHQXxU3WmMHAS6J0PWD6XJ5h1BKevD6a/+WHT4OKwFPju+if1d98WRcDXy5FTSj3OVQJ4NL177lthPFGe40pzz68t5pQRAzoDhRYnQ2zgyUpfZioUbwEIbezW1UCseH1+kE2fTMun+e/RrxVMu0W/hfw2WQwOo7OI6IBGitwIvj3+g== 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=y9l1w2+8VjOrBlskqMt7yo18vaGBhUWmQAJn+1ysJ1c=; b=gxuJ7H5ff1mYr/KSSDu5Bkt73UprVAo7tNyz7r/d0yXGjJCKkRVrxSFUhws3vRIXKsTSEKtbQL93HlQHv+kuxtbWih38iM4Isc7OmlP1AGgX7LKck0aaVQcOiKCQY7ynC/qhYim3WBW/h/Guj/8bxx7KRa16gaEpJbCI/JK0SjFtwSpk7JJSJqj0oCgwpwRscbrbZAZB64E6ASesWN4CywyWlvlaaVAq8QbszhrCF5xtbPNFcEIsypSUi86EqQ+VfHthlMj/6wbgWugM0vZb6vnnsiEcgygg5f5wY4U7ks+QLQMEjHrnrSnDkMI6oan1rFzFLrBZG8Fc5n0sSQ323w== 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=y9l1w2+8VjOrBlskqMt7yo18vaGBhUWmQAJn+1ysJ1c=; b=K38rieJdsCoI5+8mLplfzMy1JTJrkQaDxABbfxeq/6vTYWrhKoFiXyExWhkGGN8UGX/zaA4Ary0uf3XxY6IKEzDbiaUeIzMPmPXzzOFfmU/WUcndY3rsYaYjHmxBkfTCl4mLu9hbfLLc/GKJzhsIcLmnbXzLSCmfNzp1GjHiyRU= 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 TY2PR0101MB3696.apcprd01.prod.exchangelabs.com (2603:1096:404:8009::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.23; Fri, 27 Oct 2023 06:25:55 +0000 Received: from PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::7723:9ad4:633e:fe0d]) by PUZPR01MB5405.apcprd01.prod.exchangelabs.com ([fe80::7723:9ad4:633e:fe0d%5]) with mapi id 15.20.6907.032; Fri, 27 Oct 2023 06:25:55 +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: [PATCH 1/2] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Date: Fri, 27 Oct 2023 14:24:39 +0800 Message-Id: <20231027062440.7749-2-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027062440.7749-1-crescentcy.hsieh@moxa.com> References: <20231027062440.7749-1-crescentcy.hsieh@moxa.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TYAPR01CA0119.jpnprd01.prod.outlook.com (2603:1096:404:2a::35) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|TY2PR0101MB3696:EE_ X-MS-Office365-Filtering-Correlation-Id: 211858a5-fcc4-4122-1483-08dbd6b59354 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m4kRvcY1QrpHjOM56jPgAXku/aep8MISR9fEyZSma6bh6f/OZmUUnEA3vPw9XR3pBUs/qHKcq5m3+vbu9M/08hufmvxxreEpZ1EvQBAq/YvPSidRPddmcuOSW0o8a3IoN6/FOw7NDmSb+c8cQR/P1KK58TqAyNWnJZhqQMuOgc5yNwEaq6MVZrdTl2+K2eVdMx6L8ce5bcR6oMeKIIDHAVHZgDvj0ZnPsINDbcnV1d9dztzWjzdRV6nofRDjG/Lk81YKb1uLZmsVo9xxyoMPRFWmscPRXSIqjy8ttZzQw6nwzPhebqzubkIHvqHW1mwUuZAcNddjjDhttHA+mOAAZOPKQJB+2bunnzEThKYViRyT744FS1KWx6Qp/PUxrVQ5KxWYOeCV+89G2FAJHZO+usxwG+lPlEMzwqicsdqP597qvzmUGMcFa6XHw0OCcWUkdm2VIF+Lp0DxTbI81ypTfsRZoXX75LJ+tefDEOaIjP8q1x5Canqkfd1n3RNA9niyLiPe3YLiCWykaQZ/dNrLUGAAYljsmrvA3bR56bsGgpLQEa/5ffqntGtt7ZdGanhGlNk0scjiz7OeXUNdxkuM3v5BXu4vvpPYs3ceYhjUSNaNDH9Kcz68hBU/L5Sk2Deu 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)(366004)(346002)(376002)(396003)(136003)(230922051799003)(451199024)(1800799009)(186009)(64100799003)(26005)(38100700002)(83380400001)(4326008)(41300700001)(8676002)(8936002)(66556008)(2906002)(66946007)(5660300002)(110136005)(66476007)(86362001)(316002)(478600001)(38350700005)(36756003)(52116002)(6666004)(6486002)(6506007)(2616005)(1076003)(107886003)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?lXopcSbmkcqN55ggVpAaEdKDRXcGOVr3HLF7ze48cCycIOrDz3z+uPsBK6Mx?= =?us-ascii?Q?+YtAX+sX8BVyzko6gg7cO+/92OhApyoqDRA8QWYMEpxgHrxEyvDcI5w4XGgT?= =?us-ascii?Q?d0ptyEyw8vurttchSnLpqgCT+Vcs0lLMsSwWtPVOYbLZ1Z96fuvga8Lgo4jC?= =?us-ascii?Q?xE+G8K6nf3oh08I9nHrlWLD1f7DkQfBSRd94+bHZaPf9c9y8Py8+oLg8w1Va?= =?us-ascii?Q?oWyQ/qCP05AA6cqBWzUCEZAMbcMP/oU38qggyP0KT2u1UzKc3PI9N1iAnsVf?= =?us-ascii?Q?MNZowRTjS6HpksLM5fgY/9rM5R8IOLpj3YPaGm5ssrYrxCEzqBgvBdw6v5yr?= =?us-ascii?Q?+VJzPnDBF/jyaiTGIBzGXYcLuUcVKzQqMT/R5KZ4a8/Ah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GDPFmlmz6OCKC7TNT+zUvcsWcEWrEsBKAY+5Ex2+NY8UGkLmCT3+cqk7C?= =?us-ascii?Q?5QY7Ry6Tsa7Z7b45ntRMKCdqPh+xKjwwxck1ikcdTNGi6ydlg3/4Dzw9PtAo?= =?us-ascii?Q?YhG4QpFOJE5/4KUJxZZfBIQw2Qo/G0cCm8+kw/z1YKQlhRCUQsDbansyyxEx?= =?us-ascii?Q?FP1xZEyUQMOnk36EQgByvy/11dIYqxMgTIiRWCspsqhJyYCh5/QGO6jhOI1T?= =?us-ascii?Q?8jdZGwwJ8i8i1h5drtZw93z6fP1gwVEq92RBbT8K++O6xQCtGPwO1kn4VQG5?= =?us-ascii?Q?1qLOI3HsHRebyLFBTQvkKrDysH0Nz98KJP/iMUORlAypASSFLh7LBK+R3nE9?= =?us-ascii?Q?Kg=3D=3D?= X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: 211858a5-fcc4-4122-1483-08dbd6b59354 X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2023 06:25:55.3980 (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: FXnfOtl8jh3PTCJNbh7JzNk6xNP/nyarxuSIEShFKxUeBa0kDLgIIe2RbePpvMtk5KC+DU/xy5pJOIGfW8qQJdSYbUc0Bj5LD3Ky79x0eX4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY2PR0101MB3696 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 26 Oct 2023 23:26:26 -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 | 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