From patchwork Fri Jun 23 09:49:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 779905 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wvDGf30BNz9sNW for ; Fri, 23 Jun 2017 19:50:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Z8moCCE3"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="PeOVu36Y"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8tlrsbjzOUtY+qeT3bECooU+LibZIE3hal7nXYm4LI0=; b=Z8moCCE30qSb/9 Y3WcnPvkKx/O7pF4IxEETW6y7QMRQyWiFRQTn6dwfymHegs8csAmaL7AeLTQxeKjTd5WL/BKQ/SyC k6nzYcpsc68UyJ5+nvAK8aMHhHwcZoGtOCg9PlJUTBmJMTihxHtFoV3IvzGbXpmEhkL/FvoLeF3cP BzpXQbb2SlWObT83AxuwN1b2I1e0ogmaDw7J+n8C7V/GCh6JKBTkya/0xYGUf6XrX/QnIqgHiEqeT tSAYJQwN/dK1IT1/WWnx3FBV/th8sowPtj+Or24tb0d5T9r6v6V6+8839cKOkQL4yJLWSF7ojYd2k hJT+VK3X1b0BKFsDpu9w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dOLEl-0006Lh-6a; Fri, 23 Jun 2017 09:50:47 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dOLEK-0005tJ-Ks for linux-arm-kernel@bombadil.infradead.org; Fri, 23 Jun 2017 09:50:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=pN0J+HqnRAXC98wkqo7Fk9B7EKB+npt764S8hi3TCWg=; b=PeOVu36YVMuLU0Iau9iuzYuSBJ L8OhGRZtt3BYRlbdqn5srSl14ArCbVkr/92GwY6qAy5odW0MT1aK/Ebgy3HgosQG3FtSg9GYglcB1 x6Ja8Br0uh5/f6wqLSMU/ebbYoHSiVI1vgXVfrObpHK/E97NNkNKx4Ajoov65dKjxfK62u8S1kjvQ ayKsJ/dEyZjB0Yf/xbX1GcXQFD3DBrL1czmReq5Npjn2sSuVcO1d6NHdSjkiPiyct4YpRJQ2lAMMc +8k+NwcCTAECwHHFQoVZb7igl+M8XkzZWMkDfB4+VdMfwcBE1QyBVbagX88TSibBsmqrEV6IohOhO LIM7cW0g==; Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dOLEG-0004SW-D3 for linux-arm-kernel@lists.infradead.org; Fri, 23 Jun 2017 09:50:19 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dOLDt-0000rI-Hj; Fri, 23 Jun 2017 11:49:53 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dOLDt-0000AQ-8J; Fri, 23 Jun 2017 11:49:53 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 3/9] serial: Add common rs485 device tree parsing function Date: Fri, 23 Jun 2017 11:49:39 +0200 Message-Id: <20170623094945.31908-4-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170623094945.31908-1-u.kleine-koenig@pengutronix.de> References: <20170623094945.31908-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170623_105016_486940_39D67F40 X-CRM114-Status: GOOD ( 22.60 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Sascha Hauer , kernel@pengutronix.de Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org From: Sascha Hauer Several drivers have the same device tree parsing code. Create a common helper function for it. Signed-off-by: Sascha Hauer [ukl: implement default <0 0> for rts-delay, unset unspecified flags] Signed-off-by: Uwe Kleine-König --- Changed in v2: - make rts-delay optional - fix prototype of of_get_rs485_mode for the !OF_SERIAL case drivers/tty/serial/Kconfig | 4 ++++ drivers/tty/serial/Makefile | 2 ++ drivers/tty/serial/of.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/serial_core.h | 13 +++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 drivers/tty/serial/of.c diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 5c8850f7a2a0..8baef5b95bed 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -14,6 +14,10 @@ config SERIAL_EARLYCON the console before standard serial driver is probed. The console is enabled when early_param is processed. +config OF_SERIAL + depends on SERIAL_CORE + def_bool y + source "drivers/tty/serial/8250/Kconfig" comment "Non-8250 serial port support" diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile index 53c03e005132..0fee8f4e36cb 100644 --- a/drivers/tty/serial/Makefile +++ b/drivers/tty/serial/Makefile @@ -7,6 +7,8 @@ obj-$(CONFIG_SERIAL_CORE) += serial_core.o obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o obj-$(CONFIG_SERIAL_EARLYCON_ARM_SEMIHOST) += earlycon-arm-semihost.o +obj-$(CONFIG_OF_SERIAL) += of.o + # These Sparc drivers have to appear before others such as 8250 # which share ttySx minor node space. Otherwise console device # names change and other unplesantries. diff --git a/drivers/tty/serial/of.c b/drivers/tty/serial/of.c new file mode 100644 index 000000000000..b24e4357661b --- /dev/null +++ b/drivers/tty/serial/of.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +/** + * of_get_rs485_mode() - Implement parsing rs485 properties + * @np: uart node + * @rs485conf: output parameter + * + * This function implements the device tree binding described in + * Documentation/devicetree/bindings/serial/rs485.txt. + * + * Return: 0 on success, 1 if the node doesn't contain rs485 stuff. + */ +int of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf) +{ + u32 rs485_delay[2]; + int ret; + + if (!IS_ENABLED(CONFIG_OF) || !np) + return 1; + + ret = of_property_read_u32_array(np, "rs485-rts-delay" rs485_delay, 2); + if (!ret) { + rs485conf->delay_rts_before_send = rs485_delay[0]; + rs485conf->delay_rts_after_send = rs485_delay[1]; + } else { + rs485conf->delay_rts_before_send = 0; + rs485conf->delay_rts_after_send = 0; + } + + /* + * clear full-duplex and enabled flags to get to a defined state with + * the two following properties. + */ + rs485conf->flags &= ~(SER_RS485_RX_DURING_TX | SER_RS485_ENABLED); + + if (of_property_read_bool(np, "rs485-rx-during-tx")) + rs485conf->flags |= SER_RS485_RX_DURING_TX; + + if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time")) + rs485conf->flags |= SER_RS485_ENABLED; + + return 0; +} +EXPORT_SYMBOL_GPL(of_get_rs485_mode); diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 64d892f1e5cd..5ba00b1be093 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -500,4 +500,17 @@ static inline int uart_handle_break(struct uart_port *port) (cflag) & CRTSCTS || \ !((cflag) & CLOCAL)) +/* + * Common device tree parsing helpers + */ +#ifdef CONFIG_OF_SERIAL +int of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf); +#else +static inline int of_get_rs485_mode(struct device_node *np, + struct serial_rs485 *rs485conf) +{ + return 1; +} +#endif + #endif /* LINUX_SERIAL_CORE_H */