Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp547191imm; Fri, 1 Jun 2018 05:43:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI1TSQdBtSg0bbRxOdhnf/k+7UcLJAopXImB6/mVv0ck2ShfWiVPDkkvWNXGa9FfTdO+J5/ X-Received: by 2002:a62:8910:: with SMTP id v16-v6mr10610218pfd.13.1527857031538; Fri, 01 Jun 2018 05:43:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527857031; cv=none; d=google.com; s=arc-20160816; b=GugcWVJ+4z0gKotgh3YW20pDzkf/YICDui3uDCCbY6iFos6Pxyir4CJ499O9e5/PfL G0ly3pplRWSaMaBLmDq61zzMfgq8MHT6DHksiz+B2EXN0VGpQpTXxQuezgIx53FyWEsh RxgOdgrPLqndmxtmTRMRLkGsRXZhxHx1QVb9FhyZTdyYpOcK80X4PokVyZ2TwYfx2L0x nWKuapMUBkNb7NF4NL9EcbSpSrKfEjqL/pVyTGqrhc2pQENFiADRgPRPFPwXDlBXiWYH MXjj8NdPUsK9ipMzFfFqarCGjTT7D1vqoH5a7yoXKilMlTJp8TSdk+5JnbnK1qZW15hI TXyA== 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=qX+KJ9g+/hP7ModID+8f7sQmj/wLBJFUmUC7D5jVptY=; b=F4XqhGJWPpvZiW5crmuJp+EzKV4pZ5BPe2k7DIDhrimZW0l8MiEOr/fVhLjoE8TV1o 0oj8iXICNSVOV9LpGhgu1EvbcnOD8B3GLJk000ahR1WcmSOyLi0ThsVnE/oCDbzXAnyQ XQ0etGAjEwUHJIZceGAPKh8v2brzGjnKhtLcnxkO1VzgeOG0jL6Nw9QRrKSFyOmirRUO BbRoApjElnUpjcSlgc7F220Ua9IrDeznVaeZaa4Z2ca/jsmtmnc4ARZ8UegBA4qLx4kv Y7v1L2FUR3pXTV10nujSfrOw3TIgj3TyVVZMgJ5igUwcTzaWMcJtGVAZxI+qfq/9pJm3 UBFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@micronovasrl.com header.s=dkim header.b=fTH7qo0B; 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 f11-v6si21200429plt.9.2018.06.01.05.43.37; Fri, 01 Jun 2018 05:43:51 -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=fTH7qo0B; 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 S1752314AbeFAMkt (ORCPT + 99 others); Fri, 1 Jun 2018 08:40:49 -0400 Received: from mail.micronovasrl.com ([212.103.203.10]:39006 "EHLO mail.micronovasrl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752231AbeFAMkn (ORCPT ); Fri, 1 Jun 2018 08:40:43 -0400 Received: from mail.micronovasrl.com (mail.micronovasrl.com [127.0.0.1]) by mail.micronovasrl.com (Postfix) with ESMTP id A3E0CB00917 for ; Fri, 1 Jun 2018 14:40:41 +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=1527856841; x=1528720842; bh=ki 5GYuq5vxUdu6v028qvM4ajfsYBhCvWQMNkEOAnynE=; b=fTH7qo0B3gDCnQ67Ek 8qjPIjLbPSsDyE7jM89Tr2TTWmICLuLqAeHgWR6kmQGhUk3C9aGmP62fEOZS3/7x u7ZiF3Cnds5HaaA6CIUdtXA+ebDeXJP/UQJvT9MwgKUE2/e4tN0kfRfgX3LFsGcZ 35nB8KOy4gPU4VOY33YJqo85U= 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 t_YEtoSdFAW6 for ; Fri, 1 Jun 2018 14:40:41 +0200 (CEST) Received: from localhost.localdomain (unknown [87.18.119.93]) by mail.micronovasrl.com (Postfix) with ESMTPSA id 850C4B00959; Fri, 1 Jun 2018 14:40:32 +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 4/8] serial: 8250: Handle case port doesn't have TEMT interrupt using em485. Date: Fri, 1 Jun 2018 14:40:17 +0200 Message-Id: <20180601124021.102970-5-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 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 95833cbc4338..e14badbbf181 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -599,15 +599,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. @@ -616,7 +617,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; @@ -633,6 +634,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; @@ -1517,11 +1519,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.0