Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1117450ybb; Wed, 25 Mar 2020 16:15:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtgmIOL/DoBd6DVkbmQTQuo4MuL8c0lW5sncY/oAyzC91hneQrUO1xvTrD6Qi2pU7mgNArl X-Received: by 2002:a4a:3e90:: with SMTP id t138mr3166912oot.24.1585178136338; Wed, 25 Mar 2020 16:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585178136; cv=none; d=google.com; s=arc-20160816; b=k6Xs5mEQJ51UK6JXYmoUsLeR87NVRApusWyJ7waLUG+N9ngXl1ttwX+oBRLG/NcFPr 3cKF6PlMLAiyK54vD2q29xGMI57NkBuytB5RxbZB3mIp7Tjnk5UIFJ3gOrT3IfhDaDUe 5pAB6hS/s2VcATuzEd2D03CSzqlyk6UetdAAMFsR8YnfvfH6hCwHzPkim8zHPN1ANH/t w9zUgCI6lVs2tc0sHLOUg0bRSFLedDDhBp/rh9hklbyLTjm+JdLHhFvNAT/VW/qBlUni Li4vVTUnRqPddhUUJCY32ej7SZ+zTCHhy50F7A1mwQHoUULfSaQgWkAYub3h/eZ4mrnM DRTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DagPcRZPh8ImYYLSgpLSsPewnSABOyI12Avt+BS/H5s=; b=mG/jq0YhZOMqjiG4XnRLCWf2MBKE5Wxts2R/tGyqrsuAHL/ey0yMKPaWYxPxfGBXCf skoU40Q/pb4Rb4c4SihnUwkL4Y1JcRZ36NrqVfBOm7P9eP//lNByaVqqnfh8PeRJzG8F j8TbxLPfRd9vYeyViuSYBaxfCu6mFmRKW2mRTyI1pYjocNv8+IHXBFa44NGPU/+ZjPsn 817pEwtqtnr1svTPhGNOkcI/sHnHFxWesOWhIown8PzS5dssPJtiQlQ8zIArRf+76JSw uJ1a7wqmE2yB+G44C/m4rTwk2SgljT5wJKzawKky189nbqA2vFLJOXk0jNn1R7AB9vd+ wvkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si256078otp.268.2020.03.25.16.15.22; Wed, 25 Mar 2020 16:15:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727775AbgCYXOx (ORCPT + 99 others); Wed, 25 Mar 2020 19:14:53 -0400 Received: from gloria.sntech.de ([185.11.138.130]:40174 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727536AbgCYXOn (ORCPT ); Wed, 25 Mar 2020 19:14:43 -0400 Received: from ip5f5a5d2f.dynamic.kabel-deutschland.de ([95.90.93.47] helo=phil.sntech) by gloria.sntech.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jHFEI-0007ug-4p; Thu, 26 Mar 2020 00:14:34 +0100 From: Heiko Stuebner To: gregkh@linuxfoundation.org Cc: jslaby@suse.com, andriy.shevchenko@linux.intel.com, matwey.kornilov@gmail.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, heiko@sntech.de, lukas@wunner.de, christoph.muellner@theobroma-systems.com, giulio.benetti@micronovasrl.com Subject: [PATCH DON'T APPLY v2 3/7] serial: 8250: Support rs485 bus termination GPIO Date: Thu, 26 Mar 2020 00:14:18 +0100 Message-Id: <20200325231422.1502366-4-heiko@sntech.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200325231422.1502366-1-heiko@sntech.de> References: <20200325231422.1502366-1-heiko@sntech.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner Amend the serial core to retrieve the rs485 bus termination GPIO from the device tree (or ACPI table) and amend the default ->rs485_config() callback for 8250 drivers to change the GPIO on request from user space. Signed-off-by: Lukas Wunner Signed-off-by: Heiko Stuebner --- drivers/tty/serial/8250/8250_port.c | 5 +++++ drivers/tty/serial/serial_core.c | 25 +++++++++++++++++++++++++ include/linux/serial_core.h | 1 + 3 files changed, 31 insertions(+) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 4440867b7d20..47c059987538 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -681,6 +682,10 @@ int serial8250_em485_config(struct uart_port *port, struct serial_rs485 *rs485) memset(rs485->padding, 0, sizeof(rs485->padding)); port->rs485 = *rs485; + if (port->rs485_term_gpio) + gpiod_set_value(port->rs485_term_gpio, + rs485->flags & SER_RS485_TERMINATE_BUS); + /* * Both serial8250_em485_init() and serial8250_em485_destroy() * are idempotent. diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 43b6682877d5..77702b6371e3 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -27,6 +27,7 @@ #include #include +#include /* * This is used to lock changes in serial line configuration. @@ -3317,6 +3318,7 @@ int uart_get_rs485_mode(struct uart_port *port) * to get to a defined state with the following properties: */ rs485conf->flags &= ~(SER_RS485_RX_DURING_TX | SER_RS485_ENABLED | + SER_RS485_TERMINATE_BUS | SER_RS485_RTS_AFTER_SEND); rs485conf->flags |= SER_RS485_RTS_ON_SEND; @@ -3331,6 +3333,29 @@ int uart_get_rs485_mode(struct uart_port *port) rs485conf->flags |= SER_RS485_RTS_AFTER_SEND; } + if (port->rs485_term_gpio) + devm_gpiod_put(dev, port->rs485_term_gpio); + + port->rs485_term_gpio = devm_gpiod_get(dev, "rs485-term", + GPIOD_FLAGS_BIT_DIR_OUT); + if (IS_ERR(port->rs485_term_gpio)) { + ret = PTR_ERR(port->rs485_term_gpio); + port->rs485_term_gpio = NULL; + if (ret != -ENOENT) { + if (ret != -EPROBE_DEFER) + dev_err(dev, "Cannot get rs485-term-gpios\n"); + return ret; + } + } else { + ret = gpiod_get_value(port->rs485_term_gpio); + if (ret < 0) { + dev_err(dev, "Cannot get rs485-term-gpios value\n"); + return ret; + } + if (ret) + rs485conf->flags |= SER_RS485_TERMINATE_BUS; + } + return 0; } EXPORT_SYMBOL_GPL(uart_get_rs485_mode); diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index b649a2b894e7..9521e23b2144 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -251,6 +251,7 @@ struct uart_port { struct attribute_group *attr_group; /* port specific attributes */ const struct attribute_group **tty_groups; /* all attributes (serial core use only) */ struct serial_rs485 rs485; + struct gpio_desc *rs485_term_gpio; /* enable RS485 bus termination */ struct serial_iso7816 iso7816; void *private_data; /* generic platform data pointer */ }; -- 2.24.1