Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp596926imm; Wed, 6 Jun 2018 02:53:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIuwxfFO1wUJ7IEJmAoVIq+xXUfWzJgA6EiefMQWPE8DfVfrXxrloAh7lCTK0OSZZ+g66uB X-Received: by 2002:a62:e8d:: with SMTP id 13-v6mr1754736pfo.63.1528278820458; Wed, 06 Jun 2018 02:53:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528278820; cv=none; d=google.com; s=arc-20160816; b=aGO2nwtpppH+4RrAkGw+BNXRnYowSGNPTlDb5YHL2jhDoDnmYTl5N9tV+nQGrTz8Am ZPksKJ80onoAHOS6M+93eBN4khcVueov1S6O4gL+HuRGv10ZtN3zquGv3P/AF/M1BvlA VD74RlN7/hvsXbey2+Tho5XiCTqWItmcHKadyGJlk9G6JYjBUrx0bEbECrlvosAKjW0Y 9TWcYivBNnSz3ebMDj6/3eCZEe8KPrPhq2sDeLEVC0pPwvR4RStCH35/jyvr/i9u8WNL FGWZx+/FBqesjcn+LB9hlB6jl6uqtiCLFP7E2WX+pD/iq2tQm4B0JOIiwB/phUosxbzU LtpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:in-reply-to:message-id:date :subject:cc:from:dkim-signature:arc-authentication-results; bh=EEbpZ5dNUHjOfuVbEdaCyuYwzfOKljE4m5A+s/R+pGU=; b=WoUVAWkCRT3CHt67BKjLd106qF5L4EAB26d7HAI+11M4rdfPkz+ZfId6X59VSXwc3+ XLqjAJh4tbjZTIji/jZdXiku5EraV6nE8kF3ryBFMgDhbJjKLtEU+psJFAmHY0pgFJHe R2hW7ofxlruHuoeq8jcGAw1+DIjBsMjasUekblzHgFhczkZF+8YpTlerGRCLZhLwxzr2 7XTOPfkhFRmK7dY9JNOyiwN5nojgMUtADZbsIsdG9VfvsqKzhdb3TRSrBAuvB24GdMTY xZNLs6O5aTMNQGZv8ahzrFi+hj4tNNsZit0Z7M6mzKoi7sQeFAExrl55zhsWu8MKXFOV eBPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@micronovasrl.com header.s=dkim header.b=KS9RXhUo; 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 p29-v6si25011997pgn.663.2018.06.06.02.53.25; Wed, 06 Jun 2018 02:53:40 -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=KS9RXhUo; 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 S932675AbeFFJwV (ORCPT + 99 others); Wed, 6 Jun 2018 05:52:21 -0400 Received: from mail.micronovasrl.com ([212.103.203.10]:56188 "EHLO mail.micronovasrl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932663AbeFFJwU (ORCPT ); Wed, 6 Jun 2018 05:52:20 -0400 Received: from mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) by mail.micronovasrl.com (Postfix) with ESMTP id C6245B0079D for ; Wed, 6 Jun 2018 11:52:18 +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=1528278737; x=1529142738; bh=Wy cJHyQ+cKu+2yqM4UhkuNK3E4S+s8kYcssbAfzKs3I=; b=KS9RXhUohlH+X9KFXg dEarxr8KT0nJ95dwpSZjo8l8I4FpkU+JPyERj3/yh20vJNnZcKREDfiZ1NpqC9l7 1UFbUC2hJkCZyzJRY3CCDPuh8d2xoRJCiSatOlCOiGH/JmisL12KthtpvgszyuDG 2X/SwL+dJ+Wl3N4FUyLoHiwuQ= 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 yLf2KvFkwibw for ; Wed, 6 Jun 2018 11:52:17 +0200 (CEST) Received: from localhost.localdomain (unknown [87.18.119.93]) by mail.micronovasrl.com (Postfix) with ESMTPSA id 4F22BB0071D; Wed, 6 Jun 2018 11:52:16 +0200 (CEST) From: Giulio Benetti Cc: matwey.kornilov@gmail.com, Giulio Benetti , Andy Shevchenko , Greg Kroah-Hartman , Jiri Slaby , Ed Blake , Joshua Scott , linux-serial@vger.kernel.org (open list:SERIAL DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/4] serial: 8250_dw: add em485 support Date: Wed, 6 Jun 2018 11:51:54 +0200 Message-Id: <20180606095156.72628-4-giulio.benetti@micronovasrl.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180606095156.72628-1-giulio.benetti@micronovasrl.com> References: <20180606095156.72628-1-giulio.benetti@micronovasrl.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 6fcdb90f616a..45366e6e5411 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -314,6 +314,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); + + 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 @@ -449,6 +479,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.17.1