From patchwork Thu Oct 4 09:08:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10625755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0F2613BB for ; Thu, 4 Oct 2018 09:09:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E099F28C6D for ; Thu, 4 Oct 2018 09:09:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D534828CBB; Thu, 4 Oct 2018 09:09:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8811E28C6D for ; Thu, 4 Oct 2018 09:09:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 370A96E596; Thu, 4 Oct 2018 09:09:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lb2-smtp-cloud8.xs4all.net (lb2-smtp-cloud8.xs4all.net [194.109.24.25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E6796E58F for ; Thu, 4 Oct 2018 09:09:07 +0000 (UTC) Received: from tschai.fritz.box ([212.251.195.8]) by smtp-cloud8.xs4all.net with ESMTPA id 7zcygC0KD0ZZE7zd3gjcz7; Thu, 04 Oct 2018 11:09:05 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Subject: [PATCH 4/5] omapdrm/dss/hdmi4_cec.c: clear TX FIFO before transmit_done Date: Thu, 4 Oct 2018 11:08:59 +0200 Message-Id: <20181004090900.32915-5-hverkuil@xs4all.nl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181004090900.32915-1-hverkuil@xs4all.nl> References: <20181004090900.32915-1-hverkuil@xs4all.nl> X-CMAE-Envelope: MS4wfOHUDIiPDYOb622JxqGz7sJ0QhlbgIFACKk/7NT6oAHxkFiQcbOnxy7Db3kaDRt9Kt/1cu0cOd6nbBDm/yBqp9TrWLPWhRMY3J5pltf9/tKhEn6XnoVY mMpL2ETAhyOzwaOWKAjjUrmiGEzH2m0qDx35DtLAFWtMwx9ZrrzHm11y0MvXWT4X1p331syuv54iia1EFWjlax7PX1uNNOBTKTdeOXX5Tfn09+Uydgfj36n5 QultK7082Qgo+PfeSNwuO0MG7+EshRGhJVOAo5n9yH100U7ZfgSqGERnB7sOomhk X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomi Valkeinen , Hans Verkuil , dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil The TX FIFO has to be cleared if the transmit failed due to e.g. a NACK condition, otherwise the hardware will keep trying to transmit the message. An attempt was made to do this, but it was done after the call to cec_transmit_done, which can cause a race condition since the call to cec_transmit_done can cause a new transmit to be issued, and then attempting to clear the TX FIFO will actually clear the new transmit instead of the old transmit and the new transmit simply never happens. By clearing the FIFO before transmit_done is called this race is fixed. Note that there is no reason to clear the FIFO if the transmit was successful, so the attempt to clear the FIFO in that case was dropped. Signed-off-by: Hans Verkuil --- drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c | 35 ++++++++++++------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c b/drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c index 340383150fb9..dee66a5101b5 100644 --- a/drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c +++ b/drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c @@ -106,6 +106,22 @@ static void hdmi_cec_received_msg(struct hdmi_core_data *core) } } +static bool hdmi_cec_clear_tx_fifo(struct cec_adapter *adap) +{ + struct hdmi_core_data *core = cec_get_drvdata(adap); + int retry = HDMI_CORE_CEC_RETRY; + int temp; + + REG_FLD_MOD(core->base, HDMI_CEC_DBG_3, 0x1, 7, 7); + while (retry) { + temp = hdmi_read_reg(core->base, HDMI_CEC_DBG_3); + if (FLD_GET(temp, 7, 7) == 0) + break; + retry--; + } + return retry != 0; +} + void hdmi4_cec_irq(struct hdmi_core_data *core) { u32 stat0 = hdmi_read_reg(core->base, HDMI_CEC_INT_STATUS_0); @@ -117,36 +133,19 @@ void hdmi4_cec_irq(struct hdmi_core_data *core) if (stat0 & 0x20) { cec_transmit_done(core->adap, CEC_TX_STATUS_OK, 0, 0, 0, 0); - REG_FLD_MOD(core->base, HDMI_CEC_DBG_3, 0x1, 7, 7); } else if (stat1 & 0x02) { u32 dbg3 = hdmi_read_reg(core->base, HDMI_CEC_DBG_3); + hdmi_cec_clear_tx_fifo(core->adap); cec_transmit_done(core->adap, CEC_TX_STATUS_NACK | CEC_TX_STATUS_MAX_RETRIES, 0, (dbg3 >> 4) & 7, 0, 0); - REG_FLD_MOD(core->base, HDMI_CEC_DBG_3, 0x1, 7, 7); } if (stat0 & 0x02) hdmi_cec_received_msg(core); } -static bool hdmi_cec_clear_tx_fifo(struct cec_adapter *adap) -{ - struct hdmi_core_data *core = cec_get_drvdata(adap); - int retry = HDMI_CORE_CEC_RETRY; - int temp; - - REG_FLD_MOD(core->base, HDMI_CEC_DBG_3, 0x1, 7, 7); - while (retry) { - temp = hdmi_read_reg(core->base, HDMI_CEC_DBG_3); - if (FLD_GET(temp, 7, 7) == 0) - break; - retry--; - } - return retry != 0; -} - static bool hdmi_cec_clear_rx_fifo(struct cec_adapter *adap) { struct hdmi_core_data *core = cec_get_drvdata(adap);