From patchwork Tue Jul 18 10:59:42 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: 790151 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vDhdnth1"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="mdMWpXWE"; dkim-atps=neutral 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 3xBcfr6QrTz9s3T for ; Tue, 18 Jul 2017 21:01:40 +1000 (AEST) 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=RNwpsAHGrURMTuxxpKaO1tc3gBHcn7paaSq6uhz4zmQ=; b=vDhdnth1FK+1l4 i2s3NL1oDDv5F4nqis7swcK3CpH2kDKu7U7gwg4k3z8IW+gJbKe43lR4+6JnWknEC7CYgeQMWPXAW jpZoQMdVv4pmTGl9NRuPm8vryHZcaq2/R6HGnvBUeBeoMMkj80CagLKLXtKi5R/Uc3tv5Xsjf+34F guH30KI+rC20WkgMewI/hatTLf0VlYi2B5ATiPo+REg7f6q0H12gt84r2vQEZ5yW9Fsk+4xidTDGo zLH4bKNomgximjc04bt85Hy8dH6Ro4h/3zerFGa6e0sapogmii6bkf/uK76t4Dh6JGbkP1T4wBZqP h5V/YpLHWvlJ5yjWap7A==; 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 1dXQG1-0002KH-UJ; Tue, 18 Jul 2017 11:01:37 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dXQFe-00020f-4o for linux-arm-kernel@bombadil.infradead.org; Tue, 18 Jul 2017 11:01:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=tZcbprnwIZOm3mW+JKrB9YHPa/mydSrrPxwPwOOE9XU=; b=mdMWpXWEoZlN876II4RD+bWegV ElxSSb2gdXNMjzaLjHvWlQElUs3ApjAAwY1PhS1gwhbYgFgYke5VowxbcXgKdTUKSoQv0aVvKfFhn zKyCjs7Jl86G9Lk7uNY/GhC73QlGDScmQpFgnq3y6W1S8ZF6PCi7YozRf9A1BvzK+mEHunCjhVMxS JccCh4WrewYEBJ+f9nJunvOPWK818LEb2pW1AAAiN0QXFVfsF71vyEwv0fXwSGpE5AMQBlxqtwkDr yfxdx1GB/M7n87Y/UKFgGf2BT7C1RvosJ90PFXI1IMT7qYs9o2zMnqgcw97V9+t4L5pbYa518nl+4 0/dBRBzg==; Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dXQEo-00031U-3d for linux-arm-kernel@lists.infradead.org; Tue, 18 Jul 2017 11:00:24 +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 1dXQEO-0007e1-MX; Tue, 18 Jul 2017 12:59:56 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dXQEN-00073y-B5; Tue, 18 Jul 2017 12:59:55 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 3/9] serial: Add common rs485 device tree parsing function Date: Tue, 18 Jul 2017 12:59:42 +0200 Message-Id: <20170718105948.21986-4-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170718105948.21986-1-u.kleine-koenig@pengutronix.de> References: <20170718105948.21986-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-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 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] Acked-by: Nicolas Ferre Signed-off-by: Uwe Kleine-König --- 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 1f096e2bb398..f7d7e4936940 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 fe88a75d9a59..a755faa25485 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..2830c688bb5d --- /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 1775500294bb..3a89e8925722 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -501,4 +501,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 */