From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32D8EC433E0 for ; Tue, 22 Dec 2020 19:52:29 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E10BB22583 for ; Tue, 22 Dec 2020 19:52:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E10BB22583 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=platinasystems.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:MIME-Version:Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=PrcEwYShT5ROb5LyqKVBWthF8vLWoCM3x0NXSt7YcLg=; b=1uGH9BUt8MFRfVWuResILJThaO Rj1zr2JY9dRpLKv4RSd4/lJKQXxBNHzFK70eAb6hBpMfHpV3HwN9CSevExO/RiZKdoJmjAyGWOpCJ PB3jjBs3DB1uvw/x25KYRIrNk9h+4SJPWpGd57UkVo+fiqhPjxA/4gLUoDf2VqO9MCVEiX/3VyX1B fKUrRoPXydS+92HAjqveS0D5H5EB7un7VBU92jVeINok56anZjpZBf7+oES1LPj5WmywQb0rCLN2o dD628IFc7uLBQ5ijtAC8P0FmXFKdynLHHwec1usnA555i11+oSc+DVv4THACFNYTzmFK2U4y5ln+e apXWZE4Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1krnga-0002rM-A9; Tue, 22 Dec 2020 19:51:08 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1krngU-0002pP-82 for linux-arm-kernel@lists.infradead.org; Tue, 22 Dec 2020 19:51:06 +0000 Received: by mail-pj1-x1033.google.com with SMTP id j13so1917300pjz.3 for ; Tue, 22 Dec 2020 11:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=platinasystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=gnrWzcZcKCPPQwHRjj320KhXxSg0ErADEbe3H1rw//0=; b=gGUrUFMiw4JWsWifL0TXf2jyogF2W8pHnJa+hyI4msW+Mh9cnxp6FXcKIxFRNMD4Jj DH8BAGHgXF6wc4ZqBJzj2PVQzGyaZdAPRPBr77Ibt2uPXm6Wmgjl0i8G5MQt+jXDGHx1 EJRJN+g0KIrsQZP02GadFsj42H1BN/PBaNLuph4my0rmWq/xt3GF0AhQjCbK1Ght+hNT uAfsziMBPy9G4q/NfE0dknSHClk1pSZZjZLF+yCa/scL2yFYMfH1gtTYyLjTlfGfg89a n1jHUIsvZp9tXlP6b7HhmVQCzgUPXfv2OQlVzFEXYBSttDt6/XkQmYyOB4TaQ2BPLgeF PMZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=gnrWzcZcKCPPQwHRjj320KhXxSg0ErADEbe3H1rw//0=; b=Nfj1ZEb91QIaPyPKKQEf1yLNaVTOPJjiPV6zMl9i8OL3yl8Oc6eQVj4dDVKQmjFnUo yVV6BGJD974/J5fvmbR9c219/z7ETAgn5p7YmFqaAmRqDXQ1EozNiqJ1T1NvpF0dkqZ+ tvDEhT1iHxKt7YCKfOgqWV8DtiMElEURjNZrEMS+dDS0EVyM8RlkB+/mEj+OmXtlT+DG hHQbJ8RTbj7L3oS9PC6CzNxv8OozcFEsN8J8koQM1QuUtZ43cAn6Ebhm+InG9zm+gVOx KzHwe28RfLsfV1ELINz1BfLZ9MYOYWhTbv1NOraCJujyhbZTbiNrNK9QnILSGpIWZwOh ItkA== X-Gm-Message-State: AOAM5301i+DA9BjXQDuxQPGREIW6xDt4cpwK5U/hYpX/Kqw4rP16ijdo F0apAKYxK02MHs8hv0Uy8UkFTA== X-Google-Smtp-Source: ABdhPJwcc+tKiFWFDEimn0YEP31KJTEdUFiu3Aj7QQrs+YsH75VI7hSfoHDyKmNPOdLKF1L/tN9FdQ== X-Received: by 2002:a17:90a:8985:: with SMTP id v5mr22935126pjn.27.1608666657981; Tue, 22 Dec 2020 11:50:57 -0800 (PST) Received: from localhost.localdomain ([207.53.255.56]) by smtp.gmail.com with ESMTPSA id b72sm20770253pfb.129.2020.12.22.11.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Dec 2020 11:50:57 -0800 (PST) From: Kevin Paul Herbert To: biwen.li@nxp.com, leoyang.li@nxp.com, linux@rempel-privat.de, kernel@pengutronix.de, wsa@the-dreams.de, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, aisheng.dong@nxp.com, xiaoning.wang@nxp.com, o.rempel@pengutronix.de, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, jiafei.pan@nxp.com, xiaobo.xie@nxp.com, linux-arm-kernel@lists.infradead.org, biwen.li@oss.nxp.com, kph@platinasystems.com Subject: [PATCH] i2c-imx.c: Synthesize end of transaction events without idle interrupts Date: Tue, 22 Dec 2020 11:48:50 -0800 Message-Id: <20201222194850.2274527-1-kph@platinasystems.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201222_145102_600089_531A9BED X-CRM114-Status: GOOD ( 17.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Only the Layerscape SoCs have interrupts on bus idle, which facilitate sending events which complete slave bus transactions. Add support for synthesizing missing events. If we see a master request, or a newly addressed slave request, if the last event sent to the backend was I2C_SLAVE_READ_REQUESTED, send the backend a I2C_SLAVE_READ_PROCESSED followed by I2C_SLAVE_STOP. For all other events, send an I2C_SLAVE_STOP. Signed-off-by: Kevin Paul Herbert --- drivers/i2c/busses/i2c-imx.c | 59 +++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index b444fbf1a262..b3e2a6a7fc19 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -209,6 +209,7 @@ struct imx_i2c_struct { struct imx_i2c_dma *dma; struct i2c_client *slave; + enum i2c_slave_event last_slave_event; }; static const struct imx_i2c_hwdata imx1_i2c_hwdata = { @@ -662,6 +663,36 @@ static void i2c_imx_enable_bus_idle(struct imx_i2c_struct *i2c_imx) } } +static void i2c_imx_slave_event(struct imx_i2c_struct *i2c_imx, + enum i2c_slave_event event, u8 *val) +{ + i2c_slave_event(i2c_imx->slave, event, val); + i2c_imx->last_slave_event = event; +} + +static void i2c_imx_slave_finish_op(struct imx_i2c_struct *i2c_imx) +{ + u8 val; + + while (i2c_imx->last_slave_event != I2C_SLAVE_STOP) { + switch (i2c_imx->last_slave_event) { + case I2C_SLAVE_READ_REQUESTED: + i2c_imx_slave_event(i2c_imx, I2C_SLAVE_READ_PROCESSED, + &val); + break; + + case I2C_SLAVE_WRITE_REQUESTED: + case I2C_SLAVE_READ_PROCESSED: + case I2C_SLAVE_WRITE_RECEIVED: + i2c_imx_slave_event(i2c_imx, I2C_SLAVE_STOP, &val); + break; + + case I2C_SLAVE_STOP: + break; + } + } +} + static irqreturn_t i2c_imx_slave_isr(struct imx_i2c_struct *i2c_imx, unsigned int status, unsigned int ctl) { @@ -674,9 +705,11 @@ static irqreturn_t i2c_imx_slave_isr(struct imx_i2c_struct *i2c_imx, } if (status & I2SR_IAAS) { /* Addressed as a slave */ + i2c_imx_slave_finish_op(i2c_imx); if (status & I2SR_SRW) { /* Master wants to read from us*/ dev_dbg(&i2c_imx->adapter.dev, "read requested"); - i2c_slave_event(i2c_imx->slave, I2C_SLAVE_READ_REQUESTED, &value); + i2c_imx_slave_event(i2c_imx, + I2C_SLAVE_READ_REQUESTED, &value); /* Slave transmit */ ctl |= I2CR_MTX; @@ -686,7 +719,8 @@ static irqreturn_t i2c_imx_slave_isr(struct imx_i2c_struct *i2c_imx, imx_i2c_write_reg(value, i2c_imx, IMX_I2C_I2DR); } else { /* Master wants to write to us */ dev_dbg(&i2c_imx->adapter.dev, "write requested"); - i2c_slave_event(i2c_imx->slave, I2C_SLAVE_WRITE_REQUESTED, &value); + i2c_imx_slave_event(i2c_imx, + I2C_SLAVE_WRITE_REQUESTED, &value); /* Slave receive */ ctl &= ~I2CR_MTX; @@ -697,17 +731,20 @@ static irqreturn_t i2c_imx_slave_isr(struct imx_i2c_struct *i2c_imx, } else if (!(ctl & I2CR_MTX)) { /* Receive mode */ if (status & I2SR_IBB) { /* No STOP signal detected */ value = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); - i2c_slave_event(i2c_imx->slave, I2C_SLAVE_WRITE_RECEIVED, &value); + i2c_imx_slave_event(i2c_imx, + I2C_SLAVE_WRITE_RECEIVED, &value); } else { /* STOP signal is detected */ dev_dbg(&i2c_imx->adapter.dev, "STOP signal detected"); - i2c_slave_event(i2c_imx->slave, I2C_SLAVE_STOP, &value); + i2c_imx_slave_event(i2c_imx, + I2C_SLAVE_STOP, &value); } } else if (!(status & I2SR_RXAK)) { /* Transmit mode received ACK */ ctl |= I2CR_MTX; imx_i2c_write_reg(ctl, i2c_imx, IMX_I2C_I2CR); - i2c_slave_event(i2c_imx->slave, I2C_SLAVE_READ_PROCESSED, &value); + i2c_imx_slave_event(i2c_imx, + I2C_SLAVE_READ_PROCESSED, &value); imx_i2c_write_reg(value, i2c_imx, IMX_I2C_I2DR); } else { /* Transmit mode received NAK */ @@ -748,6 +785,7 @@ static int i2c_imx_reg_slave(struct i2c_client *client) return -EBUSY; i2c_imx->slave = client; + i2c_imx->last_slave_event = I2C_SLAVE_STOP; /* Resume */ ret = pm_runtime_get_sync(i2c_imx->adapter.dev.parent); @@ -800,10 +838,17 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id) status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); ctl = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + if (status & I2SR_IIF) { i2c_imx_clear_irq(i2c_imx, I2SR_IIF); - if (i2c_imx->slave && !(ctl & I2CR_MSTA)) - return i2c_imx_slave_isr(i2c_imx, status, ctl); + if (i2c_imx->slave) { + if (!(ctl & I2CR_MSTA)) { + return i2c_imx_slave_isr(i2c_imx, status, ctl); + } else if (i2c_imx->last_slave_event != + I2C_SLAVE_STOP) { + i2c_imx_slave_finish_op(i2c_imx); + } + } return i2c_imx_master_isr(i2c_imx, status); } -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel