Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp692549ybh; Wed, 18 Mar 2020 07:28:04 -0700 (PDT) X-Google-Smtp-Source: ADFU+vufSfzmpMds4NAegjcH9ecvVKiNVRVzIidyVlOz3wsez9Ao9FFAXb82fqgVfHstJByOxYAm X-Received: by 2002:a9d:69c5:: with SMTP id v5mr3869364oto.228.1584541684816; Wed, 18 Mar 2020 07:28:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584541684; cv=none; d=google.com; s=arc-20160816; b=I4V1yIvchMHVSuBwR1WzTNGBmFa/QgSP7eoqbKc8BqKx5tywM8m62si1hiX7auA+Qf J3skq61Wr+X0cc98TzLH4262vPG6vJpj6hogjSgKAdif4pwm9zgWNiAVX4D12BtDiPO1 SzCKLdrb9d9NT2MEaxfD5wJCz88ViknzAPmjPVoN8z5vDqX1sPDo068fzGdY2if4tteV Pm2SnJZITDRDSpuKjogkpMLp8M99x9XriILmofEb5MRDOPmRAx6bzf/2JlOYHC75n+j8 khEq6sxnT5G6pq8tIYiUTmj2rg6EJz8k9NBnd//HUewCbnX/PWLYK0xbedymheWGQ8GX DIbQ== 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=8K8I+Otal/EP3HidRsN9ctG6m7vBMHBaeLRTW6bZ6EA=; b=CMjm68WyWweZcmUDaipk+2yC1zT2w76PvQdsdG7x4bi0GwbWB/GU6inwiuDGqUM1Ii PDM9kGotALDxKZYXIKx07NGrRG4/GhLuPy5ceMCH7GqJykM9sTUDcGkO0Hq67Kq8HR67 4Vr8EXzkKVa1rhyqzI3t8BzOjuICHX9gaEuTfQ10IU52Zj0LDtgtsAGkkNCUC72L+q9M G4HnfhcetSKkjQqrdNCPLDaHh53bgR/5V/63au6pwZ8xNFxRYIZNsAWqOdLmlJ4gsmFO TD1YeyCg8VVU5i/7TLsJ4b7m7jyna/o+dEEGZmChAhBXiWcwmV84mqSbct9i4JUsLlcO nIAw== 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 11si3327452oij.162.2020.03.18.07.27.52; Wed, 18 Mar 2020 07:28:04 -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 S1726596AbgCRO1R (ORCPT + 99 others); Wed, 18 Mar 2020 10:27:17 -0400 Received: from gloria.sntech.de ([185.11.138.130]:37358 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbgCRO1A (ORCPT ); Wed, 18 Mar 2020 10:27:00 -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 1jEZeo-0004YX-AJ; Wed, 18 Mar 2020 15:26:54 +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 3/7] serial: 8250: Handle case port doesn't have TEMT interrupt using em485. Date: Wed, 18 Mar 2020 15:26:36 +0100 Message-Id: <20200318142640.982763-4-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 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 Signed-off-by: Heiko Stuebner --- drivers/tty/serial/8250/8250.h | 2 +- drivers/tty/serial/8250/8250_of.c | 2 +- drivers/tty/serial/8250/8250_omap.c | 2 +- drivers/tty/serial/8250/8250_port.c | 30 +++++++++++++++++++++-------- include/linux/serial_8250.h | 1 + 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h index 50a4c174410d..9e049d2a039e 100644 --- a/drivers/tty/serial/8250/8250.h +++ b/drivers/tty/serial/8250/8250.h @@ -190,7 +190,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); /* MCR <-> TIOCM conversion */ diff --git a/drivers/tty/serial/8250/8250_of.c b/drivers/tty/serial/8250/8250_of.c index 92fbf46ce3bd..c77ab44a5468 100644 --- a/drivers/tty/serial/8250/8250_of.c +++ b/drivers/tty/serial/8250/8250_of.c @@ -64,7 +64,7 @@ static int of_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_omap.c b/drivers/tty/serial/8250/8250_omap.c index 836e736ae188..241322900298 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -734,7 +734,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 67aa3a2a9afa..3d1d8490bc42 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -605,15 +605,17 @@ 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. @@ -622,7 +624,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; @@ -639,6 +641,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; @@ -1475,11 +1478,22 @@ 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 { + int val; + + if (serial_in_poll_timeout(p, UART_LSR, val, + (val & BOTH_EMPTY) != BOTH_EMPTY, + 100000) < 0) + pr_warn("%s: timeout waiting for fifos to empty\n", + p->port.name); + } em485->active_timer = NULL; diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h index bb2bc99388ca..c4b4469c272b 100644 --- a/include/linux/serial_8250.h +++ b/include/linux/serial_8250.h @@ -79,6 +79,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; /* variant has TEMT interrupt */ struct uart_8250_port *port; /* for hrtimer callbacks */ }; -- 2.24.1