From patchwork Fri Jan 26 17:27:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Farouk Bouabid X-Patchwork-Id: 192717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp27904dyb; Fri, 26 Jan 2024 09:30:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEF923XPyXlN2fh8PKgWfD3Y07D69PmDS/h7OAvXokZk/VKTU5s7DvaFZz4vzHPh01/+JpJ X-Received: by 2002:a17:906:3bd6:b0:a29:b31d:1dc6 with SMTP id v22-20020a1709063bd600b00a29b31d1dc6mr290805ejf.6.1706290236095; Fri, 26 Jan 2024 09:30:36 -0800 (PST) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v21-20020a170906565500b00a2fba12f3aasi793185ejr.8.2024.01.26.09.30.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 09:30:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40435-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@theobroma-systems.com header.s=selector1 header.b=HNzWbr8C; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-40435-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40435-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=theobroma-systems.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B20901F25224 for ; Fri, 26 Jan 2024 17:30:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4EFB2209F; Fri, 26 Jan 2024 17:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=theobroma-systems.com header.i=@theobroma-systems.com header.b="HNzWbr8C" Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2054.outbound.protection.outlook.com [40.107.7.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E1DA20B34; Fri, 26 Jan 2024 17:28:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.7.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706290128; cv=fail; b=izgo9P/2aRMCpmfn+aKX0gHhFqpX+I0USUVqUq5LAzS3+2NZXDX3lRQjIbEpQ3hOYkFpTU2MEYWSqe4DMz6y5b0Ndx7GHvrwj8c3eee5oLQlBIJ633eZsLOdhQVWqPMRoujCfjZiSwF6Hr1mUCKp+G2OluwDibCZh8pM1g1/Bt0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706290128; c=relaxed/simple; bh=gQQH//f+vjvcV1BTOIw+1BNw+SB4UGsB6T8Ukg/QAoY=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=XiKV3lQdZAkWAJcCWrvJLM31EvqNXnNnQ9lEXWqSnTvz5XV0cQqXsTvYdHuC8n8mcPk4jp4ri/a/ULLcYSvknXGNEDI6WOIeNM+5PkahYLKnY7fX771vSoA1N4ra6OUiKvpveGKNugMB8DHMcI4hp1CJ8LiFdptsvjDAbcXxv5M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=theobroma-systems.com; spf=pass smtp.mailfrom=theobroma-systems.com; dkim=pass (2048-bit key) header.d=theobroma-systems.com header.i=@theobroma-systems.com header.b=HNzWbr8C; arc=fail smtp.client-ip=40.107.7.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=theobroma-systems.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=theobroma-systems.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GRVN94Vw9339URPIliIaCmMj7oGHPnrcY3AzEwuQQTjJN3tDFNgFsx77TBseLCIquHQqU/azttB3yg4O8yITG7/qVSL3KqPz//i4PObgj76V9JlWHcV8/xwVZifVMLbdkasRijw9/2QOH1O33pW2qA4G2rTiWk2bD2tr8qCNcHProUzKgYEAB0okUig5b3JamQglyYAqkoJEynrYamONGmBuNN9iXYcxaelQwBARHhqpS0Je5OFuTNapIVRsF1zpD2L9472GnpxHkJqQ6kzaqpvRfXnj75qeBxgCrBeNBqS6DsklLm53rBhm6HWon833+nfVUWNGLWfN1FctTUcJWg== 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=S3D13ylB0RrpOulRlqk3gxsVJgIMce4Ga9Ejbqk3QrY=; b=ZJXdOuIP2X+KKagaZT88SgS3VD5IiOgISbvrcADBaP3qpFcPzdUTCZ7Nz50iimQ7DE4QS2oXJxdlZq/WfksCdZ8Ys0MHWAP/IdXvCMQpAvaHHbpzna6+ja1WZUQj+p2p49IC0I43etdzL9v1nLjiT4WGRuLy9bW4LjP0HYfGczJG/qWWgZonpqaHb9Kp2g/Bu4jyu2IWS43Zl/YutSRqjlFCyUUxL/+Y1LHujfDmjeAPcjOn4NOSg8zFgtJWA8fo/yp2jky0RpdMLR+a0RUXcjN3aAvpv5PXPJeFB1/e4T7Y+yf7yC/GUXVLRqjXIrW3evBuNyyVxIqoMxgmB3crRA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=theobroma-systems.com; dmarc=pass action=none header.from=theobroma-systems.com; dkim=pass header.d=theobroma-systems.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=theobroma-systems.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S3D13ylB0RrpOulRlqk3gxsVJgIMce4Ga9Ejbqk3QrY=; b=HNzWbr8C1Q6f1ZhC+lfUfyV/SUdGmm5WJNWm5atRvMd1dr1scx55W0DvUxrmUkYNitihUATkNe9CyTRfUc4dXLsfRt35QfFbcfFhXDeYuWfCkGTXZWByUAejRxZ/QEdAl2JnjA8uDEI623Md0HCvpTjqHsVJM8mnROzY0z7VEP2N5IOqfUwUAQ0l+9fI6p4jzHDcwJjZQBaX3nmE476eCgs5pP73YEqozVNUCjRnq2X/hAcAD7jykWXbCsz7f89X17HP5Rb9neEa2sZM1ZyAeZHrBgGzfT7PSbuNg9J+SNDLQZlHBKyLF7zvQbyq7eQUx7uzudZumaVXvswwZ7Ligw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=theobroma-systems.com; Received: from VE1PR04MB6382.eurprd04.prod.outlook.com (2603:10a6:803:122::31) by DB9PR04MB9820.eurprd04.prod.outlook.com (2603:10a6:10:4c3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.26; Fri, 26 Jan 2024 17:28:37 +0000 Received: from VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::d4b1:cea8:7085:ec50]) by VE1PR04MB6382.eurprd04.prod.outlook.com ([fe80::d4b1:cea8:7085:ec50%4]) with mapi id 15.20.7228.027; Fri, 26 Jan 2024 17:28:37 +0000 From: Farouk Bouabid Date: Fri, 26 Jan 2024 18:27:45 +0100 Subject: [PATCH v5 4/6] serial: 8250: set rx-enable gpio state when rs485 is disabled Message-Id: <20240126-dev-rx-enable-v5-4-5d934eda05ca@theobroma-systems.com> References: <20240126-dev-rx-enable-v5-0-5d934eda05ca@theobroma-systems.com> In-Reply-To: <20240126-dev-rx-enable-v5-0-5d934eda05ca@theobroma-systems.com> To: Greg Kroah-Hartman , Jiri Slaby , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner Cc: Rob Herring , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, quentin.schulz@theobroma-systems.com, Farouk Bouabid X-Mailer: b4 0.12.3 X-ClientProxiedBy: VE1PR03CA0003.eurprd03.prod.outlook.com (2603:10a6:802:a0::15) To VE1PR04MB6382.eurprd04.prod.outlook.com (2603:10a6:803:122::31) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6382:EE_|DB9PR04MB9820:EE_ X-MS-Office365-Filtering-Correlation-Id: 304068e2-a041-46b0-d5d1-08dc1e943a44 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EQr4VWAF/W7dDyMfAk/JQ42oPwHA+wJL6h9ynoxuHuHNrZK34wtXtbQ3gFcaTucjnyCDknWR7zPG+ifntJ2nZDsQ5/3CkIHxoFs/P2Iu/dcmnOIaDzRk2CP0Ix/JlCkuiUuc2jCjXP48anJvaqcctKz0ztLotMcQ9/pxkVIXX9bLKwV/wjayw0AAi/EY7eO4g3PyTSslM0+GdovI64+eBOkYOeOZ8njbkOpdPaNU7utkIoryGngRpfrRqrXwQEd+kXB8CRYsjDHl67YdKoI8t/spm7LwFOwGVQPsstyhT90teKi4is7rxoDWbbM5mxNUxHgzXH50DYlt6I3/WQsaHc6v8D99qf5L2XY/PUn2CC0XZ7/cDGcbNCw5W+kBtsR2OA4/LCkYnaetRrapCETqe8B5muE/fwzWfkdXgTNkepq0pBR3xxn7+DqOUE/sv0rYyRCSn/BTnrTyM0m7NAKHRr7qw6epx53zB8YJ1PdQMC5ApdBmHPyr/vBqh0o+R+1jeUhSQPWkYL8A3VhWNNmFBq1z1OU28yLHHho82jNYpNCpvuI2vbG9qxEEDY3BC/r4cueuahT0tY/JOScXwtPgzVvdrVxB6qC20qXFsOiSlwgO2d8d/8Zh+lKj/O90xGsF X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6382.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39850400004)(136003)(376002)(366004)(396003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(36756003)(478600001)(8676002)(4326008)(7416002)(8936002)(66556008)(54906003)(5660300002)(6486002)(44832011)(66476007)(316002)(2906002)(110136005)(66946007)(86362001)(6666004)(38350700005)(52116002)(6512007)(38100700002)(83380400001)(6506007)(2616005)(41300700001)(26005)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bK9EehCCW4/tltVXleE8todqNU3/?= =?utf-8?q?bUJaoy8T2jgdchYag7xom4biXp3NFZdno+o5RJ+3tq0y0UX8zkvl+QiNdnbAQ0tsS?= =?utf-8?q?h1ahDfiRfWxGhmuLzoVELwB7jshdIib6iq1fmRdtQYQR4O+7GgIHD4lyL3K3/j8zG?= =?utf-8?q?V/Jig6FIzBg3Zrg9rg9Lq4XTLtUA8Zx7j5lAJlhCPn716O41LIcNVUFrkH95/Em+D?= =?utf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-8?q?FxzdjpQOdLx//azwaPB7B/z4eTRn+RkR/YrifbJL6ztIB2qaY4heKFp7BUmTCjTs4?= =?utf-8?q?nR6QhULAGuKrNsjvIQC15Y0h2QH6C6kJy5iRMqQi71E1cDBzULg1QE9prRqTU80Q2?= =?utf-8?q?PyDv7vzdaIo6rnAAOaP9Yq6zeRwhsKH1PSIreglzjsfsbmvC2ntNAN6qXEAKFAxtp?= =?utf-8?q?nqsAqdhxuSPfpGJKD2DtnptrGeFUvND6B35x9irWDL4PP2AETVrjN8LpBP3Db8RnI?= =?utf-8?q?OEEAKqnGIVcxVSYpreFSyTslkg5St3TeMKvhCoiu6zWGBq0Q9qSU2J4g/2yiVs5r4?= =?utf-8?q?mWQ2OwgzXg/nCFgp0SetOMBAwXakvh3f9eCO6/X5uLdLMXthpq+Lba61r7k75mzAN?= =?utf-8?q?IFLet8z1JUMLvRWR1GsLGQTo4Ja2NeWjsfL0AimzoWedpxEqacYenBCnJ+CvnI5nZ?= =?utf-8?q?o5kDLESryVX0Ob2nbq1wf7mePryGNR2OSj9E76MgDagUlVgqzlGblEo=3D?= X-OriginatorOrg: theobroma-systems.com X-MS-Exchange-CrossTenant-Network-Message-Id: 304068e2-a041-46b0-d5d1-08dc1e943a44 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6382.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 17:28:36.2306 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5e0e1b52-21b5-4e7b-83bb-514ec460677e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: svuCXIXvdO8RLh0wz1RLk+l8SHeqGUJ0lyzbJ3/mS8V9tShn+ziAKvmiYVFWvvXRvtog6mOwWdA6Bcc1N0D6vhoLgIasNcDLdg0WQnOVftg6YA6kfoYvT3JlC3ZM9hRc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9820 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789174990852483554 X-GMAIL-MSGID: 1789174990852483554 Add the possibility to de-activate rx-enable gpio when rs485 is disabled. This defines the state of RE or DE/RE signal when em485 is disabled. Signed-off-by: Farouk Bouabid --- drivers/tty/serial/8250/8250_port.c | 4 ++++ drivers/tty/serial/serial_core.c | 6 +++++- include/linux/serial_core.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 54d8f809b81e..fbd0212d2397 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -582,12 +582,16 @@ static int serial8250_em485_init(struct uart_8250_port *p) */ void serial8250_em485_destroy(struct uart_8250_port *p) { + struct uart_port *port = &p->port; + if (!p->em485) return; hrtimer_cancel(&p->em485->start_tx_timer); hrtimer_cancel(&p->em485->stop_tx_timer); + gpiod_set_value(port->rs485_re_gpio, !port->rs485_re_gpio_inactive_when_rs485_disabled); + kfree(p->em485); p->em485 = NULL; } diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 8067d20c5275..abcba88dd5a7 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3663,7 +3663,11 @@ int uart_get_rs485_mode(struct uart_port *port) if (port->rs485_rx_during_tx_gpio) port->rs485_supported.flags |= SER_RS485_RX_DURING_TX; - port->rs485_re_gpio = devm_gpiod_get_optional(dev, "rs485-rx-enable", GPIOD_OUT_HIGH); + port->rs485_re_gpio_inactive_when_rs485_disabled = device_property_read_bool(dev, + "rs485-rx-enable-inactive-when-rs485-disabled"); + + port->rs485_re_gpio = devm_gpiod_get_optional(dev, "rs485-rx-enable", + port->rs485_re_gpio_inactive_when_rs485_disabled ? GPIOD_OUT_LOW : GPIOD_OUT_HIGH); if (IS_ERR(port->rs485_re_gpio)) { ret = PTR_ERR(port->rs485_re_gpio); port->rs485_re_gpio = NULL; diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 364583203a24..fa5a92b56360 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -585,6 +585,7 @@ struct uart_port { struct gpio_desc *rs485_term_gpio; /* enable RS485 bus termination */ struct gpio_desc *rs485_rx_during_tx_gpio; /* Output GPIO that sets the state of RS485 RX during TX */ struct gpio_desc *rs485_re_gpio; /* gpio RS485 receive enable */ + bool rs485_re_gpio_inactive_when_rs485_disabled; struct serial_iso7816 iso7816; void *private_data; /* generic platform data pointer */ };