From patchwork Fri Jan 26 14:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Farouk Bouabid X-Patchwork-Id: 767174 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2040.outbound.protection.outlook.com [40.107.22.40]) (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 628E31CD1F; Fri, 26 Jan 2024 14:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706281112; cv=fail; b=Yi6iQ3W3JBlhsc5Ev8Crpp1Ocy1NsHfczrsB2f4q+FiiFqP039v2Asl4oczHpue7Oib798ZDTLUcYpiKcKrps2hWeirrYuU88KtLWkgAreo6UlVjQ3SeZb9cJzYwDQu3c7vTHXEFk2QUQz0gO0wyfWY4chsbyBj1uZFbzzBzzs0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706281112; c=relaxed/simple; bh=KOYx3HqUw7l2CpCi9YA/OeonY3wOAz99gPL5b470tyc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=IKckgdBf2pc3zdFHJM7DWfiwd1x+UGj2Z4S0c6DMS3QkMZeIjVw+mkv/nntmoNaSbshg2wm83DPew9+86KY6veG0F4R0hAWIYDw5u1veQ69H+lOOJOvkmJJ7JTf45jsOoJaeixDV/f11czKp8R6t8rO3tp/Z4+Qw02rEpm80ixI= 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=IU8jxQHF; arc=fail smtp.client-ip=40.107.22.40 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=theobroma-systems.com header.i=@theobroma-systems.com header.b="IU8jxQHF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jJlgeLV+KopdFamoZVVisgk5eg9lpyvwFBsiUYTzZoI2Pf7j8S5w9WvpdfpxD0gUTaSYPO0wk6d8vwzo33IZn9Wh+6wU1SUrRHjR49yUaw4xyUSYSYusFmCx8Da/irxrzMMDoIa0Qe/PY8JQm9E7TxT6Nm+zu8j1/8d6yKj23mSM3D8LlUizJ3gGvsYW/ryjjCvIRirk+FcxSPM+hL9gl65B/Ka7cbXOCTq+8xyfYhqjh4kDsTMPadRsjLUJ0SNr4050ETlHhChius05dnTCyJojDpl2Aw7b/Q2rUF8gg60fzvMz48qGfpEt97kpOZ/Il9KV+YtF9GRTPyk1aPWYUw== 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=bTLh7Dd/7uz1m4CtqrTzye9JHtHx9qlYpEWKaOA4UaE=; b=T+Mm3fBuhzKo/mL389j333IFGLqU2Xw+Ykcu7S/CGLngyZIViCUJy4rclGZc4qFKVtc50Nw4tUUPIk3jeFmJN9XH/I7MRadk6MGwSd+sFqZO811roNnBNY7e/GG5HvoaL5AfSAVF9mg5LImDn7knjSVRVQcXJ3MkCbLtpd3V0/tkfyn859ZrTNecrf3mpUSahhWXi3VkILBkZ8Up2YX1wgC90ig8FrxRC+DHobNbiVc432cQrEwclHkTTQ+maOsbhKPjq/uWGY50iynobnLnT6z4xx/oEpzZxE2bTtYefg0GhGNzMzDRaPA1gqa4bZbzU8m7DpOxn1F5gr0w+qaiRg== 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=bTLh7Dd/7uz1m4CtqrTzye9JHtHx9qlYpEWKaOA4UaE=; b=IU8jxQHF0UjIr1OPl2XJlVJMh/MxZPuOBjF+17GljZM5PCZ2yBcHJZqc66F59a/3Zn1pgmM3ofYPw+Ykxk+y86nltCwFtjz7KWhDnJZFsrRlU5Itvp+gh5Vzyc9NGrlxT1R3RVNF3KztOr0/bcq7mut2mS8Ap1a89lcMmtvZ6XdtfuNTxm5xGtp+ORB7lvj3Vl2BhW2jD/eWdHJBoyw6Oa3dhVLituLXoM5ZfM1rO27CRUR6132yPrBTIMA8pgSpJRsbeVNb4j7kDtvM7KdQqtvqbGZo3c2sioBJ7odO+eXBERFBGSYX2FWbA7PaE1zpDqs0l4wStRXDnBEGzWXqsQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=theobroma-systems.com; Received: from AM0PR04MB6371.eurprd04.prod.outlook.com (2603:10a6:208:178::19) by GVXPR04MB9735.eurprd04.prod.outlook.com (2603:10a6:150:118::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Fri, 26 Jan 2024 14:58:26 +0000 Received: from AM0PR04MB6371.eurprd04.prod.outlook.com ([fe80::e130:6c40:23e5:9a8f]) by AM0PR04MB6371.eurprd04.prod.outlook.com ([fe80::e130:6c40:23e5:9a8f%5]) with mapi id 15.20.7228.022; Fri, 26 Jan 2024 14:58:26 +0000 From: Farouk Bouabid Date: Fri, 26 Jan 2024 15:55:13 +0100 Subject: [PATCH v4 4/6] serial: 8250: set rx-enable gpio state when rs485 is disabled Message-Id: <20240126-dev-rx-enable-v4-4-45aaf4d96328@theobroma-systems.com> References: <20240126-dev-rx-enable-v4-0-45aaf4d96328@theobroma-systems.com> In-Reply-To: <20240126-dev-rx-enable-v4-0-45aaf4d96328@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: VI1PR06CA0114.eurprd06.prod.outlook.com (2603:10a6:803:8c::43) To AM0PR04MB6371.eurprd04.prod.outlook.com (2603:10a6:208:178::19) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6371:EE_|GVXPR04MB9735:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c0ebeb1-be25-4032-f3ba-08dc1e7f3fc1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ikwHT/+cbQmtqAhpOtEGbU0vuw5FSbJMS7eJfTaLYFPoWCsop7taknZ6ampf5edwpbP0iEBHkIZ30g1NjumSDQZRhYGudootMhwyuDKSasZF5mk6Tln0Kdvrt53NFT3We1I2rEQeg2l/+UG2VJ778purf7kyIE6HA8veHAL81Pr3NAOAEGyw7gvX+bUs0Uve+l8Qr0yJuJGQAk9TVFku18ZxiWeKgfSWqHaKg7/y4rzJE8t2L9bi53NH2Qeqkc+pXZnA6S5l1mXP12XMkdVn5H0TCuq7J5i+4twOQCIWzh9qZSE7XzJ+t9Dxw9S8wNt8Hu1sKSvkNJ1UZRpoDa7+6eR+Rp5XQfFdQzfXH2fEQJPqjQ2xgeq7+Sl6FaD0v5ZA8FA8hlxD3vWQs0fXDO46rvrxFWMiQXdnw/TEdB/tdeEmGFi9WU/lU0bkxqSYrnuYWIruodiWrYBUxvgyjk6u2o8XUJDjZ3omivzJ2o5WvBxhl2nWU4mOMytV06+pGbQuBPANHoSuU4UIbrnPYexP0koy1GKiQnmh3BUb489VEzO1eyDrHsrSSfP7vdIka+TFVsZSyOOw47khx7YS+0I0Mk+S56f2TSyygj0W4l/Nnc97xR05D1jSOqxVcFMbro1J X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR04MB6371.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366004)(396003)(346002)(136003)(39850400004)(376002)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(66476007)(54906003)(66556008)(86362001)(478600001)(38100700002)(6486002)(6506007)(36756003)(38350700005)(41300700001)(52116002)(4326008)(8676002)(8936002)(26005)(2616005)(316002)(5660300002)(66946007)(6512007)(6666004)(7416002)(2906002)(44832011)(83380400001)(107886003)(110136005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?/OdYXZkEpT2CesioDC0mXe+w8gDB?= =?utf-8?q?SAoMVUhkU/eRyU8pQRmc0mxd2aSPnTwW4eXwwbnPDlH7zxfUMYdzcFzxfkLVVOLnM?= =?utf-8?q?HBYjsW0QbmtDn236U5pOXuwYw3A3JHSxabXWMW4L8LjHJJoYLuPZEVQWfwO8JLlH+?= =?utf-8?q?8Lk8MOp79j/NAo3zPemw5BaqFPrK1w5OJclZTU/fCyp9/gE22+tXdrK42o/6ezECX?= =?utf-8?q?LkO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izmyRbX+UdPznaIQqLfHUxiUjXG01b25L0UjPJrETnqEk3fprtJsOmRN19pOtZJ?= =?utf-8?q?9vH32XBEnpTYCJj5+VcxwWcT99c9xhKNDox2E5meabmZYzQUujUf7BaJ8R9Y3vdxt?= =?utf-8?q?BUOAJaaxEPh2i0DOC0tR3XjZN6NTwdGOKYBwG1HwJyKTyDzJxnoF1Wl7xgvLPYN8j?= =?utf-8?q?iyS1BJ5FrpFl1U9rAVKBY87aZlshWgHjv/Wx/WrucXESJcrRSBYXqbvE74L5r8Zyf?= =?utf-8?q?CcktAwrXfhRPRLTV+wHFo3RD6kD2MmGewVoG+i9ib1ZbIvF47My/4muUyp1DtSyrL?= =?utf-8?q?I3HAH2pbxw1z+XZxaBKs2f9r5GyXagniKx9fPvqFuqSyd9wJ3/Km/3qrVaf+fJgb1?= =?utf-8?q?nPHP7I2pIbeQGY2inGX5UFUEd8aWTgGhdhXsTJjPQdW+rj3w0+nm9QQa6BZXQ/oiG?= =?utf-8?q?qyDI9sQOGKAPmXCJiv8Y26z3qYy+No9GZntQtaAH5SObQODDmWjjLB4=3D?= X-OriginatorOrg: theobroma-systems.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c0ebeb1-be25-4032-f3ba-08dc1e7f3fc1 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6371.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 14:58:26.0485 (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: clzWHEw8xOlS8yBTA2WH9Q4a/FbnYMFn5A0nbIv37DXvRUcuhoPkhhbCpHhh1IhQ2Ubp2UrofvkN9fi36W7PMrLYVncfjvAm8hp9X1m/TFmzDPmJxibZFX+CWEXo0Xw7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9735 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, 11 insertions(+) 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 47aeece985f3..6460646cf83c 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3663,6 +3663,12 @@ 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_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 */ };