Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp641782imm; Fri, 1 Jun 2018 07:13:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJdJr/D3P92h/23C8Rz7ETJ8OskjKAlwxvXcI/f1nxewTuCuq+7EAyvz7YNX4RXgps0jqwP X-Received: by 2002:a63:7043:: with SMTP id a3-v6mr9034934pgn.206.1527862386540; Fri, 01 Jun 2018 07:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527862386; cv=none; d=google.com; s=arc-20160816; b=Q9h4q8ZWqCuL3nmIWYY3b2RKBU6zd1u/BmDw48+2hr9Bj34WUFOlaAi9qmyb7O+fpE off+Th7b3aRAIq8CDZlcwhT/8Xs/9C3ZHdbmdl2ohbD5BkWVznRomsIR1qwku+/TT6pQ eBJFjHfnmJD/IJG8gPudM+tIkLZzm/kbl851LwdL2kPQywd98yv9j7t4Ibtyd4+wYyLF FCrAOr0WfF5drX8BMbTPsyeOcIQqpt22G6riPXHjpmasHgMNow3Y2vZ8u+C5Hfho0yh7 QEbBCe0n0NOTL1bD6wots+lgdo2tg0fc2ceW7DWUNxPGRcHuMs+tXOHTkH5Bc+Cgv69k rk2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=0MSJ1L/Qi5fqLVoT0ECwQEW3ZlKeQeRzISpV9r/CuXA=; b=XWHlgw01QxaimiXb6l+/LNa8iGSxXqDmOnU8lEiI5dau89cQkp1awqz9ztG4lJ/hzx MMeF16xfiEZSXAs7BFuBATArVNPjLB4rGxS3f0sVmT0lWrVO6hWD8Q8MNVzVYquT4euw 8X7Y9KGJEE9LWyFVx9argznclkEbIlEp6u5fsWyiTF4sAE2XCMeN9k5+ZeW6BnCnrope HmFxg90mmf0c2Oe2QVpTZ+kR9VH7oAcFTm9HRRuRI2ihNH9aICd5mQUgr/H4NeXX+25M NrTjInXL/08JiWiIgpEDK90xALxyt+GL0DtOn8CpRPyulviPK6/PFEQ4+Q+QvECO7vJQ nQVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@micronovasrl.com header.s=dkim header.b=Y3fCzRKX; 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 x1-v6si20225395pgp.422.2018.06.01.07.12.51; Fri, 01 Jun 2018 07:13:06 -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; dkim=temperror (no key for signature) header.i=@micronovasrl.com header.s=dkim header.b=Y3fCzRKX; 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 S1751985AbeFAOMV (ORCPT + 99 others); Fri, 1 Jun 2018 10:12:21 -0400 Received: from mail.micronovasrl.com ([212.103.203.10]:44088 "EHLO mail.micronovasrl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751687AbeFAOML (ORCPT ); Fri, 1 Jun 2018 10:12:11 -0400 Received: from mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) by mail.micronovasrl.com (Postfix) with ESMTP id B55E2B0095A for ; Fri, 1 Jun 2018 16:12:09 +0200 (CEST) Authentication-Results: mail.micronovasrl.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=micronovasrl.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=micronovasrl.com; h=references:in-reply-to:x-mailer:message-id:date:date:subject :subject:to:from:from; s=dkim; t=1527862329; x=1528726330; bh=At wRJwyKranLcYGNocvo2M/fplfe4iSRfWI4Lk2kVl8=; b=Y3fCzRKXv65xkUJT5g 71mN43s9yCV9pKU7BiETXs0DgtAxbf/73tvS3qVTgQps+v37p5j1kvpjbG8k+fvB bf1v+Vhf4sXgpqGiWnbhxSv8OWCiqAylFbRy7iBPS28gOQ9ap7YGrAJICPdOGpdG be1WfiSvOoqWvNSbGLyw9k2bQ= X-Virus-Scanned: Debian amavisd-new at mail.micronovasrl.com X-Spam-Flag: NO X-Spam-Score: -2.9 X-Spam-Level: X-Spam-Status: No, score=-2.9 tagged_above=-10 required=4.5 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9] autolearn=unavailable autolearn_force=no Received: from mail.micronovasrl.com ([127.0.0.1]) by mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id fKbLnMN2ODLV for ; Fri, 1 Jun 2018 16:12:09 +0200 (CEST) Received: from localhost.localdomain (unknown [87.18.119.93]) by mail.micronovasrl.com (Postfix) with ESMTPSA id E0ABBB00959; Fri, 1 Jun 2018 16:12:03 +0200 (CEST) From: Giulio Benetti To: Greg Kroah-Hartman Cc: Jiri Slaby , Andy Shevchenko , Kees Cook , Matthias Brugger , Allen Pais , Sean Young , Ed Blake , Stefan Potyra , Philipp Zabel , Joshua Scott , Vignesh R , Rolf Evers-Fischer , Aaron Sierra , Rafael Gago , Joel Stanley , Sean Wang , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Giulio Benetti Subject: [PATCH 2/2] serial: 8250: Add SERIAL_MCTRL_GPIO support to 8250. Date: Fri, 1 Jun 2018 16:11:58 +0200 Message-Id: <20180601141158.93817-2-giulio.benetti@micronovasrl.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601141158.93817-1-giulio.benetti@micronovasrl.com> References: <20180601141158.93817-1-giulio.benetti@micronovasrl.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes mctrl signals can be connected to pins different from HW ones. User serial_mctrl_gpio helpers to align HW signals(RTS, CTS, etc.) with gpios-rts, gpios-cts etc. Signed-off-by: Giulio Benetti --- drivers/tty/serial/8250/8250_core.c | 6 ++++++ drivers/tty/serial/8250/8250_port.c | 18 +++++++++++++++--- include/linux/serial_8250.h | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index 9342fc2ee7df..c2bc906ffdf4 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -41,6 +41,8 @@ #include "8250.h" +#include "../serial_mctrl_gpio.h" + /* * Configuration: * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option @@ -1036,6 +1038,10 @@ int serial8250_register_8250_port(struct uart_8250_port *up) if (up->dl_write) uart->dl_write = up->dl_write; + uart->gpios = mctrl_gpio_init(&up->port, 0); + if (IS_ERR(uart->gpios)) + return PTR_ERR(uart->gpios); + if (uart->port.type != PORT_8250_CIR) { if (serial8250_isa_config != NULL) serial8250_isa_config(0, &uart->port, diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 95833cbc4338..3004aa3ef4e5 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -40,6 +40,8 @@ #include "8250.h" +#include "../serial_mctrl_gpio.h" + /* * These are definitions for the Exar XR17V35X and XR17(C|D)15X */ @@ -567,6 +569,8 @@ static inline void serial8250_em485_rts_after_send(struct uart_8250_port *p) else mcr &= ~UART_MCR_RTS; serial8250_out_MCR(p, mcr); + + mctrl_gpio_set(p->gpios, p->port.mctrl); } static enum hrtimer_restart serial8250_em485_handle_start_tx(struct hrtimer *t); @@ -1591,12 +1595,17 @@ static inline void start_tx_rs485(struct uart_port *port) mcr = serial8250_in_MCR(up); if (!!(up->port.rs485.flags & SER_RS485_RTS_ON_SEND) != !!(mcr & UART_MCR_RTS)) { - if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) + if (up->port.rs485.flags & SER_RS485_RTS_ON_SEND) { mcr |= UART_MCR_RTS; - else + up->port.mctrl |= TIOCM_RTS; + } else { mcr &= ~UART_MCR_RTS; + up->port.mctrl &= ~TIOCM_RTS; + } serial8250_out_MCR(up, mcr); + mctrl_gpio_set(up->gpios, up->port.mctrl); + if (up->port.rs485.delay_rts_before_send > 0) { em485->active_timer = &em485->start_tx_timer; start_hrtimer_ms(&em485->start_tx_timer, @@ -1957,7 +1966,8 @@ unsigned int serial8250_do_get_mctrl(struct uart_port *port) ret |= TIOCM_DSR; if (status & UART_MSR_CTS) ret |= TIOCM_CTS; - return ret; + + return mctrl_gpio_get(up->gpios, &ret); } EXPORT_SYMBOL_GPL(serial8250_do_get_mctrl); @@ -1987,6 +1997,8 @@ void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl) mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr; serial8250_out_MCR(up, mcr); + + mctrl_gpio_set(up->gpios, mctrl); } EXPORT_SYMBOL_GPL(serial8250_do_set_mctrl); diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h index a27ef5f56431..7872f11d4b04 100644 --- a/include/linux/serial_8250.h +++ b/include/linux/serial_8250.h @@ -134,6 +134,8 @@ struct uart_8250_port { void (*dl_write)(struct uart_8250_port *, int); struct uart_8250_em485 *em485; + + struct mctrl_gpios *gpios; }; static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up) -- 2.17.0