From patchwork Wed Oct 18 09:17:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Crescent CY Hsieh X-Patchwork-Id: 736152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3527C46CA1 for ; Wed, 18 Oct 2023 09:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229994AbjJRJVC (ORCPT ); Wed, 18 Oct 2023 05:21:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229840AbjJRJUz (ORCPT ); Wed, 18 Oct 2023 05:20:55 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2063.outbound.protection.outlook.com [40.107.255.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2C611B; Wed, 18 Oct 2023 02:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WN6ZJxYw26BcpEkTwoabR2IfxLGuIV/sHvcxlwCi+k9OG+MAEqBIaxksU049oSbBzpAAWC6EJNi/eEp/YZnkdegCU/zZNq2+IeftrkOviVTy1dlAb1IqhBlEWzEf7dNKWDpo+k0OdaPsLcb/5zEt10UAtG3rOoEV9tjh/UL5MveEpqIVs3BiC4zDNZj2mOplPEI7wKEj79nCrAoHptcomYYB+ZfP5ZWTOzzDcFDdwYHCEHggOP5YCGtSuP+300HgjK67YX6TNI/T7lKkuQtLXRolZ9NzOEwHwc/6SrEz39rU2CSHIRrkWTLDP/X9CqAbknGhrFhHAIZDGgOu6rfZyg== 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=oAjUELYMBcGULCn3tUw5EcpfML3Vo2DajzAqo9cbDsY=; b=nb9xc+mMMLo6FCBLizmm7/jyE+MQIsitpgUdYprOZscIvO9JVTWzo84rDdsmoRqRI7Oj4ZF9Xrnic1iOuEXKpiXGf+LN47gZQQYE9s3ISTglMSSlIa+/0CjgPK2hUeV20RWUAqudaDzaWboCRIPJ5chUZVnev1pckhCc4S3nnDyHaF1th1Rw4i/YK1dLzGFkC7IiSrrQVk9ByDy9i4UeDZcYs7jnIx8MyKRArM/AItALrYLe1AiTXBEf+N1bAg+Y9LYAbRrugUI7vnmbG35EoP8q63UaCA984Gki6t6wdtAP/OpUZJ9jI+S0jIJmRLV7z7jizl/NUPUP3g7uxBOYyA== 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=oAjUELYMBcGULCn3tUw5EcpfML3Vo2DajzAqo9cbDsY=; b=bVTQV/WQ6J29A5ULmMiLOYP3r/LcDerHFx3ey57M8bLGPExaE/XDgl9bZewOHiQDJ90Q7NRVISlQWvsDzE8whusJ4igbVl8Zh7RJb4iKwwoTTSvelgRRvKmOpfc/X26YeSw9RJXFk3Z/LJHnon27mhObq+swr5XjQX/sN/yevns= 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 SEZPR01MB4134.apcprd01.prod.exchangelabs.com (2603:1096:101:46::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.21; Wed, 18 Oct 2023 09:20:44 +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; Wed, 18 Oct 2023 09:20:44 +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 v3 4/6] tty: serial: 8250: Add support for MOXA Mini PCIe boards Date: Wed, 18 Oct 2023 17:17:37 +0800 Message-Id: <20231018091739.10125-5-crescentcy.hsieh@moxa.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018091739.10125-1-crescentcy.hsieh@moxa.com> References: <20231018091739.10125-1-crescentcy.hsieh@moxa.com> X-ClientProxiedBy: TYCP286CA0015.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:26c::19) To PUZPR01MB5405.apcprd01.prod.exchangelabs.com (2603:1096:301:115::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR01MB5405:EE_|SEZPR01MB4134:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b953646-0ecf-4295-ce9a-08dbcfbb816f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MIIlt0+OPsX5sYv90CqVr/oeVQS6nwfw+/BNUpTQ9JBse1fXhy6KSXYK37JP4uf19iqIMcpoz3Eii12b0JiVtJmkRfEJidwcer6QXsJAj0sCOvK4AL9DB/yCPt56BNRR0z3EsB/wVskYxNbIsQRLF8VQut3KQ1zpmmQO2zjGw6uAQqh/uikH70Zsu6H8ed4wkuXxe63LbhtS146yFXybLFvRvRtox7Mm+MDLnCjKVykE4QT0Ae+DCaxAfP0TkEaTRsScbgwn5Cdg4+VNQKRE69zcGn+NcwObvoNEJLVNpMKi4N/+gmMoXaQ1/ZnBvEP+BB5L58N8OalJ8jmlI1DruYmPjw17hJW9NXmsO6JGR++1KrDFrw6qtJf2RqNA2FETXyx1rvM84/ZKyK+w55HqqBCVon2/2afbpATJu82AVN5cpbSwCccqp0zwhujAZxbCTnBK3I7+CpNRIzDj78z4pJbtxrM4YlpHxTyl49MOcbnOG3f+m/+P7lfUlBv5SwcszYiWH8Pffn0WusD1phHZvCY1yzWLm2YOFrO+jczf6Mnu3mwI2BQOkGXS48GRHgRT0kG8gM/ywtww03ZgWQhFH4NoSry7gqFlN2N3Tfujy3z7JmByzmde2H2hNeHGY50H 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)(366004)(396003)(136003)(376002)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799009)(107886003)(38350700005)(6666004)(6506007)(52116002)(6512007)(6486002)(508600001)(66476007)(110136005)(316002)(26005)(36756003)(1076003)(66556008)(66946007)(2616005)(41300700001)(38100700002)(5660300002)(8936002)(4326008)(8676002)(2906002)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gZbG57ydpqcyqvZ7Hg0QFah4n6cTBQOu95C7hf43ZLMtAlTwJUpD/rBkIwNl1NN6ZdHku6YRORdsWR1ukq2/sAnf/u8CAkmmGlEwhj6g1DhVmeBFRReNTsTb91ag74nzZjYhhlBtJ6ntWaavoKpL0VeqX/kQ7Rt+mxLh2lqJgkVZEfXH8LC0mEo5e38fLl0PwWtdM0qaqzw/6l26q2JkUqAfoLikJ5aNAYBPMlOS0A0VJIWmsPnsV+q2pK45ox2MPWStS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vVH3uzY+q2OkXGt3jFS0ytFcEptEaK+tCRg7cI7DC7pB+TSZWrOunKFYVrL8EoDX86QmmESg2Q9NllTNNVJGsvk9V5HsV2l28Qq21k7HaBOw89Tsuf78n3TnKKTcaCJubIawYawbu9Ws6CfRqt2anfj4HkJSpAsLh3LTfbg6MQW6DZPzFtvy/G58ZWcXumsiD4Vd6ciyOSrK+UYxjSeaHXiZeAC6BT1ATQaR8LbtnRxUW7qfTOSOd14OWJpVayndaJToJaDTCG+Pt1SHxIdNA== X-OriginatorOrg: moxa.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b953646-0ecf-4295-ce9a-08dbcfbb816f X-MS-Exchange-CrossTenant-AuthSource: PUZPR01MB5405.apcprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 09:20:44.1952 (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: 3jU+3vuSJ1dtgJHwbbdA0Iryc8ve+2arpVIz8sOZFALXnSdqjhhH3FAC9QSkMwagxx3YT/2vvCXg4yIiQ+GbFoMsCttF5b9aAKrAFSFiCAA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR01MB4134 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Add support for MOXA Mini PCIe serial boards: - CP102N: 2 ports | RS232 - CP104N: 4 ports | RS232 - CP112N: 2 ports | RS232/RS422/RS485 - CP114N: 4 ports | RS232/RS422/RS485 - CP132N: 2 ports | RS422/RS485 - CP134N: 4 ports | RS422/RS485 Signed-off-by: Crescent CY Hsieh Reviewed-by: Jiri Slaby --- drivers/tty/serial/8250/8250_pci.c | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c index ef23f1c6d..b2be3783f 100644 --- a/drivers/tty/serial/8250/8250_pci.c +++ b/drivers/tty/serial/8250/8250_pci.c @@ -83,14 +83,20 @@ #define PCI_DEVICE_ID_MOXA_CP102E 0x1024 #define PCI_DEVICE_ID_MOXA_CP102EL 0x1025 +#define PCI_DEVICE_ID_MOXA_CP102N 0x1027 #define PCI_DEVICE_ID_MOXA_CP104EL_A 0x1045 +#define PCI_DEVICE_ID_MOXA_CP104N 0x1046 +#define PCI_DEVICE_ID_MOXA_CP112N 0x1121 #define PCI_DEVICE_ID_MOXA_CP114EL 0x1144 +#define PCI_DEVICE_ID_MOXA_CP114N 0x1145 #define PCI_DEVICE_ID_MOXA_CP116E_A_A 0x1160 #define PCI_DEVICE_ID_MOXA_CP116E_A_B 0x1161 #define PCI_DEVICE_ID_MOXA_CP118EL_A 0x1182 #define PCI_DEVICE_ID_MOXA_CP118E_A_I 0x1183 #define PCI_DEVICE_ID_MOXA_CP132EL 0x1322 +#define PCI_DEVICE_ID_MOXA_CP132N 0x1323 #define PCI_DEVICE_ID_MOXA_CP134EL_A 0x1342 +#define PCI_DEVICE_ID_MOXA_CP134N 0x1343 #define PCI_DEVICE_ID_MOXA_CP138E_A 0x1381 #define PCI_DEVICE_ID_MOXA_CP168EL_A 0x1683 @@ -1957,6 +1963,49 @@ pci_sunix_setup(struct serial_private *priv, return setup_port(priv, port, bar, offset, 0); } +#define MOXA_PUART_GPIO_EN 0x09 +#define MOXA_PUART_GPIO_OUT 0x0A + +#define MOXA_GPIO_PIN2 BIT(2) + +static bool pci_moxa_is_mini_pcie(unsigned short device) +{ + if (device == PCI_DEVICE_ID_MOXA_CP102N || + device == PCI_DEVICE_ID_MOXA_CP104N || + device == PCI_DEVICE_ID_MOXA_CP112N || + device == PCI_DEVICE_ID_MOXA_CP114N || + device == PCI_DEVICE_ID_MOXA_CP132N || + device == PCI_DEVICE_ID_MOXA_CP134N) + return true; + + return false; +} + +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; + u8 val; + + /* + * Enable hardware buffer to prevent break signal output when system boots up. + * This hardware buffer is only supported on Mini PCIe series. + */ + if (pci_moxa_is_mini_pcie(device)) { + /* Set GPIO direction */ + val = inb(iobar_addr + MOXA_PUART_GPIO_EN); + val |= MOXA_GPIO_PIN2; + outb(val, iobar_addr + MOXA_PUART_GPIO_EN); + /* Enable low GPIO */ + val = inb(iobar_addr + MOXA_PUART_GPIO_OUT); + val &= ~MOXA_GPIO_PIN2; + outb(val, iobar_addr + MOXA_PUART_GPIO_OUT); + } + + return num_ports; +} + static int pci_moxa_setup(struct serial_private *priv, const struct pciserial_board *board, @@ -2633,6 +2682,7 @@ static struct pci_serial_quirk pci_serial_quirks[] = { .device = PCI_ANY_ID, .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, + .init = pci_moxa_init, .setup = pci_moxa_setup, }, { @@ -5349,14 +5399,20 @@ static const struct pci_device_id serial_pci_tbl[] = { */ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102E), pbn_moxa_2 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102EL), pbn_moxa_2 }, + { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102N), pbn_moxa_2 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A), pbn_moxa_4 }, + { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104N), pbn_moxa_4 }, + { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP112N), pbn_moxa_2 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114EL), pbn_moxa_4 }, + { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114N), pbn_moxa_4 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A), pbn_moxa_8 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B), pbn_moxa_8 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A), pbn_moxa_8 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I), pbn_moxa_8 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132EL), pbn_moxa_2 }, + { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132N), pbn_moxa_2 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A), pbn_moxa_4 }, + { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134N), pbn_moxa_4 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP138E_A), pbn_moxa_8 }, { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A), pbn_moxa_8 },