Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp546584imm; Fri, 1 Jun 2018 05:43:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKMkEtCF5S43IGcEUWvTQFvNDtFWZLjs7JXPLFQYdEyBO8B3Q0UIJVuUcnsGVEj9gDMKUC3 X-Received: by 2002:a63:780d:: with SMTP id t13-v6mr1414272pgc.93.1527856988099; Fri, 01 Jun 2018 05:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527856988; cv=none; d=google.com; s=arc-20160816; b=UC8AUMJVPgXCATc7JA4Sq/H8ltFxELnUJ3qw8iufvrfrxRxkpk2AaH70nw/BQtesJV Ic+iVJv7dQuZ0w6VkVTVGxkSziHW2rbeukEGCNs8HNTyWA9iymNPLE4HMpj6kycQtnlv BzqAT9zJAc7iW+7epsFH8lN3R0bnuU9ZprWnFLbVBAwRCH15JXcUQcPGXWMqeQW/+gIO uLFyHyOKhMcEfFpXMpvW7Nykkmml6FKUs+u05n2Ebt6sr3yG+iqpaADqhHgnIFQESDXA lKQHCTuNKusgf09c9POBH/Hjq+jMXtkgFDI2GYbhE1rQZf9cbpYSP5LZ+QGVYCnsKAmg 9BKw== 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=twnBsn1tvfvkDnNmVbi1w70zgnxzEshngXYb4dbBbOk=; b=QgSMQhLOd27pI7B1GUz7UeafgI4Gk6Sb6tRQgtsybyFcInsQvhhBF8XJPawrTgYJMw 6PWAf3v7elz4BpW125rDUmMS79kDa4UrTtPbhfj7IPErNMSHcI4wlhrBKTY1Xo9v5G+i 2Teq/1I6qugvy1wudV8oYQcao5CUOavUlfXxQYHtyFb/9ed38yLidpbI8+POH3Qr7ilr bpMoaVE+XGrzC+UTB2lCBMTKK9RzjkkKytmgbi1mdFWjZNv/ufVo7wYuYADUOZkOpIF6 9/zuLca3yuXUP7/3Wjc1oaKWeiIHSY6D1hxXaKVlQC6BQrxn18FATapXu1UTT8j2njLk vENg== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@micronovasrl.com header.s=dkim header.b=IzxMEHc0; 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 bj5-v6si38009613plb.67.2018.06.01.05.42.53; Fri, 01 Jun 2018 05:43:08 -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=IzxMEHc0; 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 S1752247AbeFAMkm (ORCPT + 99 others); Fri, 1 Jun 2018 08:40:42 -0400 Received: from mail.micronovasrl.com ([212.103.203.10]:38620 "EHLO mail.micronovasrl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752128AbeFAMke (ORCPT ); Fri, 1 Jun 2018 08:40:34 -0400 Received: from mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) by mail.micronovasrl.com (Postfix) with ESMTP id 63FAAB00753 for ; Fri, 1 Jun 2018 14:40:33 +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=1527856832; x=1528720833; bh=I1 oLk+2uJxL8RHT96SITkYmBdt46FdO4KD0yRy6ScUc=; b=IzxMEHc03VBoRObjJi Cm5VslJ337WupWcNHoCkupyRtaBuRw9wU0zovN1z5Zn4dG8ss+R18tWR+P1FsznW SBhutjbJ6P/csa3jlfOgYAudgnEYq/YoWouKedXkqL0NiqMkKIFJE2euGc51XFjU xj0DAfgWU3sqYheRE8QnXWhEQ= 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 kX0heBS5sxxj for ; Fri, 1 Jun 2018 14:40:32 +0200 (CEST) Received: from localhost.localdomain (unknown [87.18.119.93]) by mail.micronovasrl.com (Postfix) with ESMTPSA id A38BFB00718; Fri, 1 Jun 2018 14:40:27 +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 1/8] serial: 8250_dw: add em485 support Date: Fri, 1 Jun 2018 14:40:14 +0200 Message-Id: <20180601124021.102970-2-giulio.benetti@micronovasrl.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601124021.102970-1-giulio.benetti@micronovasrl.com> References: <20180601124021.102970-1-giulio.benetti@micronovasrl.com> 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.0