Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp692425ybh; Wed, 18 Mar 2020 07:27:57 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvf2R+MVj0MW8mkGrNLE0ZJ9LWazyDCl+Jxskh2DZDi/d9SnWzzTbp67Iyt3u/RdU7cAN/X X-Received: by 2002:aca:75d5:: with SMTP id q204mr3460189oic.9.1584541677450; Wed, 18 Mar 2020 07:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584541677; cv=none; d=google.com; s=arc-20160816; b=FzuJnkZTkaE6kTqKSh/rTGdRe05DSm50HWhd8AGxL0FupLqvTbPkj93MnQrYVLbB7h kDik9LoxeSBKiXPlGgbF72Ka8xVdqWVndiD8st3TMAA5MUAByIGcPVPjZqhO4hc0VuFA CyBDxSUinCn6TCC/yny4X0oFY6qRbHPXHkVLfoBZ3vNCbpHQuldyVzxJwK+nSez8rapP /dsQkkI8Cxip/KcwFR/ln1ps7GqKSPEPyW4JEFATEUDr9MuLceiLD4w6h/mdlvAMtqYK LPBiox9S57C0QapDF4LTCDE3NeEKKlenf2yFBcncHMBdXw8z7WyftTi+QLTBa3fQUCIb vI1w== 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=vdySHBXDhfaNfR9+E+Q4fYUwajyC0ObwrKYD+OBEFis=; b=QoDIvFysA8zuRKuTwkeXFddSlrIUzVBShGwSI0uU/IKwsE/i07mO3/t75T6P64MRjt T/EoxRheSF+5SdhPQHMQs63BnNtmXonJZ8rMX55QSDlS+IENnMDRY0koAWopuvU+WDMS QUf2cLRCxNhBPMyAP6MG7pfsxXCjchpeaEGVPC5Ycgnf+MIN3gTgtghKYiWGVYkLRoBG FHdgzNSxGQ+QygVaYQvIXiZLYaMN7hiX4YBk68otNLRWdHt654Uzz3tjf392rqamy3Z0 xb2s3dzfbnJ1UF5EHOdXAsb5EylzpDBMQEO/eZtYwm0tsnIBfYF4Upo4SM3j2KwtassN R/IQ== 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 53si3310184otd.15.2020.03.18.07.27.44; Wed, 18 Mar 2020 07:27:57 -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 S1727176AbgCRO1G (ORCPT + 99 others); Wed, 18 Mar 2020 10:27:06 -0400 Received: from gloria.sntech.de ([185.11.138.130]:37372 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbgCRO1C (ORCPT ); Wed, 18 Mar 2020 10:27:02 -0400 Received: from [94.134.91.63] (helo=phil.fritz.box) by gloria.sntech.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jEZep-0004YX-P7; Wed, 18 Mar 2020 15:26:55 +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, Giulio Benetti , Heiko Stuebner Subject: [PATCH 6/7] serial: 8250_dw: add em485 support Date: Wed, 18 Mar 2020 15:26:39 +0100 Message-Id: <20200318142640.982763-7-heiko@sntech.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200318142640.982763-1-heiko@sntech.de> References: <20200318142640.982763-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: Giulio Benetti Need to use rs485 transceiver so let's use existing em485 485 emulation layer on top of 8250. Add rs485_config callback to port. Signed-off-by: Giulio Benetti Signed-off-by: Heiko Stuebner --- drivers/tty/serial/8250/8250_dw.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index 1c72fdc2dd37..7023b656658d 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -320,6 +320,36 @@ static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios) serial8250_do_set_ldisc(p, termios); } +static int dw8250_rs485_config(struct uart_port *p, + struct serial_rs485 *rs485) +{ + struct uart_8250_port *up = up_to_u8250p(p); + + /* Clamp the delays to [0, 100ms] */ + rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U); + rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U); + + p->rs485 = *rs485; + + /* + * Both serial8250_em485_init and serial8250_em485_destroy + * are idempotent + */ + if (rs485->flags & SER_RS485_ENABLED) { + int ret = serial8250_em485_init(up, false); + + if (ret) { + rs485->flags &= ~SER_RS485_ENABLED; + p->rs485.flags &= ~SER_RS485_ENABLED; + } + return ret; + } + + serial8250_em485_destroy(up); + + return 0; +} + /* * dw8250_fallback_dma_filter will prevent the UART from getting just any free * channel on platforms that have DMA engines, but don't have any channels @@ -417,6 +447,7 @@ static int dw8250_probe(struct platform_device *pdev) p->serial_out = dw8250_serial_out; p->set_ldisc = dw8250_set_ldisc; p->set_termios = dw8250_set_termios; + p->rs485_config = dw8250_rs485_config; p->membase = devm_ioremap(dev, regs->start, resource_size(regs)); if (!p->membase) -- 2.24.1