Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp596722imm; Wed, 6 Jun 2018 02:53:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKbUD7yBKyeFXR590BmJSXvolE42zINVtKJBAoC9x8rufpNHuCj9Ai/Aq1zIOGUcqjUqiER X-Received: by 2002:a62:fb14:: with SMTP id x20-v6mr1792060pfm.48.1528278800429; Wed, 06 Jun 2018 02:53:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528278800; cv=none; d=google.com; s=arc-20160816; b=uVXpZ56/DcHMDAbYUaIuukpc5pzv7n+q6pC32EJv/SlLeAcVmZxWENSjn3niRPDHdH I5cHVR8+sz0MLNhRFkVU4vtp+ARQxF4cKlIBrr8GNNpHoSFyEAKTBkJMeloRNfwphm4k Ojwv5XNsgRtTU7/yVulwqJTzsRKXJbjZd0zvRo/ZTzwD9MXJHOl8NXAlJKzi7jLR+Scv Ru2XLgyWHHMV2MlDNBxU9FBdWCoII6nCelwz4OyICQ+FyxHiN35FNeK0l3G5vw0uenmp A71285nQeGRZP95lGRHhJGbpNI8ilXAkSp0AQ7lUJQ77tD2mPZFzI4FsEKhiMVg9kROI +L+A== 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=JAgpjGajN/SS9hn+VgMipNL32d1pTXjf0B1tZN5fZko=; b=CAHlkbXZoqmNof0BN+t015zVbbE3LkQM0db6oogPqAF/aj3IkYKSJUkqe41rwFzoFz rAFIQp/HOxtP5GUkiHC1NHuOfD7RRRZg3T1suW5JlPyK6MAttrRv67qqK3YB0+e0jIOM ioNE6ZXChpTeeyy5skEt3UNwyaaKmfIpP4Xc53nkSztwG5/hl4BDJd5h06vw5S89CdOY fSbb4ugFzUwHi4aHSQNfnNJXo4mDLagHf8GBjeCQP9KDS9Stc/nBaZIDyvYfbqQjmJPs 4ywGifis0w7CXOPG74oGCPHSQxxq5UWaZHLy9tQNmIWSrrICWAn877qTqOfufVGGqm8c vmYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@micronovasrl.com header.s=dkim header.b=WgVNXVyO; 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 z77-v6si11821585pfk.340.2018.06.06.02.53.06; Wed, 06 Jun 2018 02:53:20 -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=WgVNXVyO; 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 S932656AbeFFJwR (ORCPT + 99 others); Wed, 6 Jun 2018 05:52:17 -0400 Received: from mail.micronovasrl.com ([212.103.203.10]:56028 "EHLO mail.micronovasrl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932265AbeFFJwO (ORCPT ); Wed, 6 Jun 2018 05:52:14 -0400 Received: from mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) by mail.micronovasrl.com (Postfix) with ESMTP id 2528DB00879 for ; Wed, 6 Jun 2018 11:52:13 +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=1528278732; x=1529142733; bh=39 uPPcIDGmVE4gau6/s7fipf9VjXG3OFtuzM+HuL430=; b=WgVNXVyOF9zFifyAsj i7fQb17ZrDjWmoaNQMWDJ4PZjzf46hWON/0rYNNHOUNShsB25mBEZhO9++4kYCLD Yx68owetLBqQIrAF/Jb7kBfJVjBtq2C1dlz0mhJ/j9zTDP0fG9m7ADkQF4ZuIONc Gf87bOhYOM90EFm23BVrrMUHA= 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 gRLNF7tIs7ka for ; Wed, 6 Jun 2018 11:52:12 +0200 (CEST) Received: from localhost.localdomain (unknown [87.18.119.93]) by mail.micronovasrl.com (Postfix) with ESMTPSA id ADE19B00767; Wed, 6 Jun 2018 11:52:09 +0200 (CEST) From: Giulio Benetti Cc: matwey.kornilov@gmail.com, Giulio Benetti , Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko , Stefan Potyra , Philipp Zabel , Ed Blake , Joshua Scott , Vignesh R , Rolf Evers-Fischer , Aaron Sierra , Phil Elwell , Rafael Gago , Joel Stanley , Sean Wang , linux-serial@vger.kernel.org (open list:SERIAL DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 3/4] serial: 8250: Handle case port doesn't have TEMT interrupt using em485. Date: Wed, 6 Jun 2018 11:51:52 +0200 Message-Id: <20180606095156.72628-2-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 Some 8250 ports only have TEMT interrupt, so current implementation can't work for ports without it. The only chance to make it work is to loop-read on LSR register. With NO TEMT interrupt check if both TEMT and THRE are set looping on LSR register. Signed-off-by: Giulio Benetti --- drivers/tty/serial/8250/8250.h | 2 +- drivers/tty/serial/8250/8250_dw.c | 2 +- drivers/tty/serial/8250/8250_omap.c | 2 +- drivers/tty/serial/8250/8250_port.c | 26 ++++++++++++++++++-------- include/linux/serial_8250.h | 1 + 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h index ebfb0bd5bef5..5c6ae5f69432 100644 --- a/drivers/tty/serial/8250/8250.h +++ b/drivers/tty/serial/8250/8250.h @@ -136,7 +136,7 @@ void serial8250_rpm_put(struct uart_8250_port *p); void serial8250_rpm_get_tx(struct uart_8250_port *p); void serial8250_rpm_put_tx(struct uart_8250_port *p); -int serial8250_em485_init(struct uart_8250_port *p); +int serial8250_em485_init(struct uart_8250_port *p, bool has_temt_isr); void serial8250_em485_destroy(struct uart_8250_port *p); static inline void serial8250_out_MCR(struct uart_8250_port *up, int value) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index 0f8b4da03d4e..888280ff5451 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -330,7 +330,7 @@ static int dw8250_rs485_config(struct uart_port *p, * are idempotent */ if (rs485->flags & SER_RS485_ENABLED) { - int ret = serial8250_em485_init(up); + int ret = serial8250_em485_init(up, false); if (ret) { rs485->flags &= ~SER_RS485_ENABLED; diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c index 624b501fd253..ab483c8b30c8 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -725,7 +725,7 @@ static int omap_8250_rs485_config(struct uart_port *port, * are idempotent */ if (rs485->flags & SER_RS485_ENABLED) { - int ret = serial8250_em485_init(up); + int ret = serial8250_em485_init(up, true); if (ret) { rs485->flags &= ~SER_RS485_ENABLED; diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index c8c10b5ec6d6..8432445c80e5 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -602,15 +602,16 @@ EXPORT_SYMBOL_GPL(serial8250_rpm_put); /** * serial8250_em485_init() - put uart_8250_port into rs485 emulating * @p: uart_8250_port port instance + * @p: bool specify if 8250 port has TEMT interrupt or not * * The function is used to start rs485 software emulating on the * &struct uart_8250_port* @p. Namely, RTS is switched before/after * transmission. The function is idempotent, so it is safe to call it * multiple times. * - * The caller MUST enable interrupt on empty shift register before - * calling serial8250_em485_init(). This interrupt is not a part of - * 8250 standard, but implementation defined. + * If has_temt_isr is passed as true, the caller MUST enable interrupt + * on empty shift register before calling serial8250_em485_init(). + * This interrupt is not a part of 8250 standard, but implementation defined. * * The function is supposed to be called from .rs485_config callback * or from any other callback protected with p->port.lock spinlock. @@ -619,7 +620,7 @@ EXPORT_SYMBOL_GPL(serial8250_rpm_put); * * Return 0 - success, -errno - otherwise */ -int serial8250_em485_init(struct uart_8250_port *p) +int serial8250_em485_init(struct uart_8250_port *p, bool has_temt_isr) { if (p->em485) return 0; @@ -636,6 +637,7 @@ int serial8250_em485_init(struct uart_8250_port *p) p->em485->start_tx_timer.function = &serial8250_em485_handle_start_tx; p->em485->port = p; p->em485->active_timer = NULL; + p->em485->has_temt_isr = has_temt_isr; serial8250_em485_rts_after_send(p); return 0; @@ -1520,11 +1522,19 @@ static inline void __stop_tx(struct uart_8250_port *p) /* * To provide required timeing and allow FIFO transfer, * __stop_tx_rs485() must be called only when both FIFO and - * shift register are empty. It is for device driver to enable - * interrupt on TEMT. + * shift register are empty. If 8250 port supports it, + * it is for device driver to enable interrupt on TEMT. + * Otherwise must loop-read until TEMT and THRE flags are set. */ - if ((lsr & BOTH_EMPTY) != BOTH_EMPTY) - return; + if (em485->has_temt_isr) { + if ((lsr & BOTH_EMPTY) != BOTH_EMPTY) + return; + } else { + while ((lsr & BOTH_EMPTY) != BOTH_EMPTY) { + lsr = serial_in(p, UART_LSR); + cpu_relax(); + } + } em485->active_timer = NULL; diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h index a27ef5f56431..9b13cf59726b 100644 --- a/include/linux/serial_8250.h +++ b/include/linux/serial_8250.h @@ -83,6 +83,7 @@ struct uart_8250_em485 { struct hrtimer start_tx_timer; /* "rs485 start tx" timer */ struct hrtimer stop_tx_timer; /* "rs485 stop tx" timer */ struct hrtimer *active_timer; /* pointer to active timer */ + bool has_temt_isr; /* say if 8250 has TEMT interrupt or no */ struct uart_8250_port *port; /* for hrtimer callbacks */ }; -- 2.17.1