Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1080203pxx; Fri, 30 Oct 2020 01:08:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVP/5BErEFda6Q4Zgv1bppzmw5Z6mJYrCWybrifngw+Xrg0x/OtZJzRQRuaOG8FWi3zK79 X-Received: by 2002:a17:906:add3:: with SMTP id lb19mr1214013ejb.130.1604045302824; Fri, 30 Oct 2020 01:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604045302; cv=none; d=google.com; s=arc-20160816; b=J05N+fMygt82JpkwJHNqldQop/VsoD6r3DicyHILrHSgYvy8kAnkAjn6AkJcTCLQpF apXRZWXifMsVTbkRPjUGYmlcvllS2BM7yUTRVSOEjAr6G46qxux2RWVo21oJ9kAsuGkR KQYIp+8XqhyquQSLBcKvTybTrs4j3IkF9QHpjv7440E4sk3L5ZFlJ1j6pdwh9uV43TR2 98sNZ0Hj4juAFJnq6XGZUqYsJDTuKWZeWMMoRmm+7E1jz2t3sVUgiIZ+D7qP7TpbYCVs RFTcwFeiQupRpPxyIID2XMiHTqxof/n0qX9FyY3ILeqJFsbJkgRCCPNfiyGYujCXmNCe gBKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MEiPWEmutrI6dcy3tVAXJ3gnd1ispPOTl60DsYN2dHo=; b=yrGBXaSOO3j/u7eIyz4aH3YyzMVuWOIGVPOjq06gUvcJfIBLLOgGuyAP+tKjyARI3k KyT2dBbfMftIjB42020DDadCkWT2D82th3eRaH76y1WgBS5tLdEed/jSXqYn2da3bn8z xNFPDFxbzn6GpOxKpAy7GO4uNwwkFuGS2592fSsr3DkAaPuN5AAGVn0W5pfuhS3WmDRP TSS6fDDEkCnsPTULLfs8Z0ApRZPsPF2JY3ktZFcbkialUmRP7G28OCtvFDL8k7V+2GVy 16kV1KamdkXNss5iDP0sT41/6nGQf7q87qYjEM1u/mYZ4d8O9ViB6VZVT9guxdWt2CtQ 9DJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vivotek.com header.s=dkim header.b="WotQ/J/m"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b24si3876559edu.147.2020.10.30.01.08.00; Fri, 30 Oct 2020 01:08:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@vivotek.com header.s=dkim header.b="WotQ/J/m"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726117AbgJ3IFV (ORCPT + 99 others); Fri, 30 Oct 2020 04:05:21 -0400 Received: from mail.vivotek.com ([60.248.39.150]:48978 "EHLO mail.vivotek.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbgJ3IFK (ORCPT ); Fri, 30 Oct 2020 04:05:10 -0400 Received: from pps.filterd (vivotekpps.vivotek.com [127.0.0.1]) by vivotekpps.vivotek.com (8.16.0.42/8.16.0.42) with SMTP id 09U7xpU0013442; Fri, 30 Oct 2020 16:04:57 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivotek.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=dkim; bh=MEiPWEmutrI6dcy3tVAXJ3gnd1ispPOTl60DsYN2dHo=; b=WotQ/J/mcdzQD0RxRICVloPESXkfclR73BuRLK9A8GAAlJqjtxYh+QemRt+r9Bix1vla limL9uNu02j68llEeaJUGEluwE9xzFNYT8L0G/BXxAUHAxpCIuclmrE+vwojxpp0EgN8 Gij5vJTYihjZAI7klonauQdd7mVeK9as4lw= Received: from cas01.vivotek.tw ([192.168.0.58]) by vivotekpps.vivotek.com with ESMTP id 34c6q166qr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 30 Oct 2020 16:04:57 +0800 Received: from localhost.localdomain (192.168.17.134) by CAS01.vivotek.tw (192.168.0.58) with Microsoft SMTP Server (TLS) id 14.3.487.0; Fri, 30 Oct 2020 16:04:57 +0800 From: Michael Wu To: Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Wolfram Sang , , CC: Morgan Chang , Michael Wu Subject: [PATCH 2/2] i2c: designware: slave should do WRITE_REQUESTED before WRITE_RECEIVED Date: Fri, 30 Oct 2020 16:04:20 +0800 Message-ID: <20201030080420.28016-3-michael.wu@vatics.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201030080420.28016-1-michael.wu@vatics.com> References: <20201030080420.28016-1-michael.wu@vatics.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.17.134] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-10-29_12:2020-10-29,2020-10-29 signatures=0 X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes we would get the following flow when doing an i2cset: 0x1 STATUS SLAVE_ACTIVITY=0x1 : RAW_INTR_STAT=0x514 : INTR_STAT=0x4 I2C_SLAVE_WRITE_RECEIVED 0x1 STATUS SLAVE_ACTIVITY=0x0 : RAW_INTR_STAT=0x714 : INTR_STAT=0x204 I2C_SLAVE_WRITE_REQUESTED I2C_SLAVE_WRITE_RECEIVED Documentation/i2c/slave-interface.rst says that I2C_SLAVE_WRITE_REQUESTED, which is mandatory, should be sent while the data did not arrive yet. It means in a write-request I2C_SLAVE_WRITE_REQUESTED should be reported before any I2C_SLAVE_WRITE_RECEIVED. By the way, I2C_SLAVE_STOP didn't be reported in the above case because DW_IC_INTR_STAT was not 0x200. dev->status can be used to record the current state, especially Designware I2C controller has no interrupts to identify a write-request. This patch makes not only I2C_SLAVE_WRITE_REQUESTED been reported first when IC_INTR_RX_FULL is rising and dev->status isn't STATUS_WRITE_IN_PROGRESS but also I2C_SLAVE_STOP been reported when a STOP condition is received. Signed-off-by: Michael Wu --- drivers/i2c/busses/i2c-designware-slave.c | 45 +++++++++-------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c index 13de01a0f75f..0d15f4c1e9f7 100644 --- a/drivers/i2c/busses/i2c-designware-slave.c +++ b/drivers/i2c/busses/i2c-designware-slave.c @@ -172,26 +172,25 @@ static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev) "%#x STATUS SLAVE_ACTIVITY=%#x : RAW_INTR_STAT=%#x : INTR_STAT=%#x\n", enabled, slave_activity, raw_stat, stat); - if ((stat & DW_IC_INTR_RX_FULL) && (stat & DW_IC_INTR_STOP_DET)) - i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED, &val); + if (stat & DW_IC_INTR_RX_FULL) { + if (dev->status != STATUS_WRITE_IN_PROGRESS) { + dev->status = STATUS_WRITE_IN_PROGRESS; + i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_REQUESTED, + &val); + } + + regmap_read(dev->map, DW_IC_DATA_CMD, &tmp); + val = tmp; + if (!i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_RECEIVED, + &val)) + dev_vdbg(dev->dev, "Byte %X acked!", val); + } if (stat & DW_IC_INTR_RD_REQ) { if (slave_activity) { - if (stat & DW_IC_INTR_RX_FULL) { - regmap_read(dev->map, DW_IC_DATA_CMD, &tmp); - val = tmp; - - if (!i2c_slave_event(dev->slave, - I2C_SLAVE_WRITE_RECEIVED, - &val)) { - dev_vdbg(dev->dev, "Byte %X acked!", - val); - } - regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp); - } else { - regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp); - regmap_read(dev->map, DW_IC_CLR_RX_UNDER, &tmp); - } + regmap_read(dev->map, DW_IC_CLR_RD_REQ, &tmp); + + dev->status = STATUS_READ_IN_PROGRESS; if (!i2c_slave_event(dev->slave, I2C_SLAVE_READ_REQUESTED, &val)) @@ -203,18 +202,10 @@ static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev) if (!i2c_slave_event(dev->slave, I2C_SLAVE_READ_PROCESSED, &val)) regmap_read(dev->map, DW_IC_CLR_RX_DONE, &tmp); - - i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val); - return 1; } - if (stat & DW_IC_INTR_RX_FULL) { - regmap_read(dev->map, DW_IC_DATA_CMD, &tmp); - val = tmp; - if (!i2c_slave_event(dev->slave, I2C_SLAVE_WRITE_RECEIVED, - &val)) - dev_vdbg(dev->dev, "Byte %X acked!", val); - } else { + if (stat & DW_IC_INTR_STOP_DET) { + dev->status = STATUS_IDLE; i2c_slave_event(dev->slave, I2C_SLAVE_STOP, &val); } -- 2.17.1