Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2434701ybk; Sun, 17 May 2020 21:52:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuFrIwd5deLknrPSRQCpr4n/ky+AA0kCf2ZFdG1MlyH68pISxhlXgYVMiHRRTfSa9Q0vSl X-Received: by 2002:a17:907:2142:: with SMTP id rk2mr13130961ejb.225.1589777541791; Sun, 17 May 2020 21:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589777541; cv=none; d=google.com; s=arc-20160816; b=ee+CZgd7Z6oYg8vRjGpmil36K55tYP09knAPKDYJKe5s3Cfu9SCy/myDLOicv3CLe5 jVlLldTcQSE4kzUQo3e5It2aSuGdTNbyGmNnU/feP/HujSYyEXUtjVozROsiQ+5PkgWs +ZbhzTG4uwiPqtsCWR9SN9uuD5sqHItPZIq1kQ7oK6gq3QSupvqsKJtkQeVZ9/hcoMvZ SSYBvl6ADkMQGue8GV7c6WRoW492YTlBjbEu6ZmfH9nadFsBSopxw9ngWYcgcE41iAEw vvKLEhOYj+LNK8wY/5g6NJqEAAfIih3HpJxAP59xpHt7f9ftsbrwoOmI8VbHXUmzeDQg gNkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hrsrYCHELVADuaGrs3vvC6Bi9asmGO2xDUqihpJuKQ0=; b=k7pd2Bai0R5sRzdkKm+G0WiBodS8icCxYHPfInycjdQSfnGCju8cbH5YzI38Xe3wOT YqDEp8MAgrXcVMelrmsLgPDZO4kGUNkaW022fsRHSbSf3KV+iNxGZma/3j+YmEG+B2MJ t15SbBO+pAGA0lFW+SboZp9XEcLNPcADM7ztHVPhehYnOUnx4xjtXiPF1os6rZZKK28W XK3/JwgvWPtKMrbNfDPj2r6arJLbh3BgKDFhD7AUjRg3epiGca0J5yBt8w8EyfdLqhHJ hNeEPeH8dcfxyihONYwx7Syyf03ZT6QKb0UFjP5cxpL6CsdhTJG/q9kTY5PrJSJv3QtM 2WBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si5951659ejz.419.2020.05.17.21.51.58; Sun, 17 May 2020 21:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726412AbgEREuJ (ORCPT + 99 others); Mon, 18 May 2020 00:50:09 -0400 Received: from bmailout3.hostsharing.net ([176.9.242.62]:49405 "EHLO bmailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbgEREuJ (ORCPT ); Mon, 18 May 2020 00:50:09 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout3.hostsharing.net (Postfix) with ESMTPS id ABE22100C0585; Mon, 18 May 2020 06:50:06 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 39BDC31442D; Mon, 18 May 2020 06:50:06 +0200 (CEST) Date: Mon, 18 May 2020 06:50:06 +0200 From: Lukas Wunner To: Heiko Stuebner Cc: gregkh@linuxfoundation.org, jslaby@suse.com, andriy.shevchenko@linux.intel.com, matwey.kornilov@gmail.com, giulio.benetti@micronovasrl.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, christoph.muellner@theobroma-systems.com, Heiko Stuebner Subject: Re: [PATCH v3 3/5] serial: 8250: Support separate rs485 rx-enable GPIO Message-ID: <20200518045006.s6e5aedgqwreqgd7@wunner.de> References: <20200517215610.2131618-1-heiko@sntech.de> <20200517215610.2131618-4-heiko@sntech.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200517215610.2131618-4-heiko@sntech.de> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 17, 2020 at 11:56:08PM +0200, Heiko Stuebner wrote: > @@ -1457,6 +1458,7 @@ void serial8250_em485_stop_tx(struct uart_8250_port *p) > * Enable previously disabled RX interrupts. > */ > if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX)) { > + gpiod_set_value(port->rs485_re_gpio, 1); > serial8250_clear_and_reinit_fifos(p); > > p->ier |= UART_IER_RLSI | UART_IER_RDI; The added line needs to be conditional on if (port->rs485_re_gpio) because the gpiod could be NULL and gpiod_set_value() doesn't check for that. > @@ -1597,9 +1599,12 @@ static inline void __start_tx(struct uart_port *port) > void serial8250_em485_start_tx(struct uart_8250_port *up) > { > unsigned char mcr = serial8250_in_MCR(up); > + struct uart_port *port = &up->port; > > - if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) > + if (!(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) { > + gpiod_set_value(port->rs485_re_gpio, 0); > serial8250_stop_rx(&up->port); > + } Same here. > --- a/include/linux/serial_core.h > +++ b/include/linux/serial_core.h > @@ -253,6 +253,7 @@ struct uart_port { > 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 gpio_desc *rs485_re_gpio; /* gpio RS485 receive enable */ Nit: I'd probably document this as "enable RS485 receiver" because it's already apparent from the variable type and name that it's a gpio, making it unnecessary to repeat that in the code comment. But I guess that's a matter of personal preference. There's something else: You need to amend serial8250_em485_config() to toggle the GPIO depending on whether SER_RS485_RX_DURING_TX is set. Right now you enable the receiver by default and then disable it when starting to transmit if half-duplex mode is selected and likewise re-enable it when stopping to transmit. But user space may write some stuff to the tty while in half-duplex mode, then immediately issue a TIOCSRS485 ioctl to switch to full-duplex mode. If the ->rs485_config callback is executed while transmitting is still ongoing, then you'll not re-enable the receiver when transmitting finally stops. The ->rs485_config callback is invoked under the uart port spinlock but the lock may be briefly released and later re-acquired by the IRQ handler if the TX FIFO is full. (Unless I'm missing something.) Thanks, Lukas