Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5243160pxu; Tue, 22 Dec 2020 11:53:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKdyX0CtQn7dn0x8cw5gr8RacgYx4YOACMtULbXlx+cV0cQ29EJtBESxD/tiCdL1Ut6FTj X-Received: by 2002:a17:906:a00a:: with SMTP id p10mr21599526ejy.312.1608666792572; Tue, 22 Dec 2020 11:53:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608666792; cv=none; d=google.com; s=arc-20160816; b=V8EtPNLdpx16A0XpDT0nSkwhPNZEYBSshj/Yoe67eki8EWzb2YuIANeyIeYQJGuZVu yO3DSMM9/aJdFPiDHrw3XWT2j7mHtdotkD4UTgM9y/NgXLHrfdvPmS1TpgAOX0RqCh2F gk2qoOiby4ZZCwuDMb2kXSbFwAbL+vdAXl4IvSpON+vw0DcEndemK41gRAp/qY7SZuxD 0a2oEN3Zt1JckNyjbxU4TsIlb8OQMI/RIpKxCOcUR04dk6f/WFgwT+RCjjEjKIL4bTww IwKrGvlwwhgr5QFdQL/IBFWVuGqe+uVBCL6QWHgVPnNGzuu8AZ41S7PBRjxVaiNPl9+F cG6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=gnrWzcZcKCPPQwHRjj320KhXxSg0ErADEbe3H1rw//0=; b=zN583S243p8gzIAlY+ZMtRrxHNOf048bqY1pC0vltv5cvT++852t6Wny2pH63syz/U ggiYj2YIzPDI7kRGWSVsa0VAb9eZ2cnzJk6fKhZ+6y4nWyIlbsnlGUM9FxI5UttYeTUb 9yrQwo/0bga28AgL4qLkXU4NJVCF4HdWj9Q6DjB96AhH9LrB7QY8xRvWO3Y1bHBfM0Ro xTEw2cYImRjiDW7Lxyee18E3D82xxqQ4i24Dq2YggWnBXUCkqgCT0TEijtz7TVkhnoVj 185oE0WYnt5NIaJ+qM3KRczFUn0ynmf+uqzEmjVN9whJjDQeLChXstUWcgNpyWC3nvFW Sv9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@platinasystems-com.20150623.gappssmtp.com header.s=20150623 header.b=gGUrUFMi; 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 e26si14943459edv.40.2020.12.22.11.52.50; Tue, 22 Dec 2020 11:53:12 -0800 (PST) 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=@platinasystems-com.20150623.gappssmtp.com header.s=20150623 header.b=gGUrUFMi; 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 S1726486AbgLVTvj (ORCPT + 99 others); Tue, 22 Dec 2020 14:51:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbgLVTvi (ORCPT ); Tue, 22 Dec 2020 14:51:38 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79E5DC0613D3 for ; Tue, 22 Dec 2020 11:50:58 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id j1so7964547pld.3 for ; Tue, 22 Dec 2020 11:50:58 -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=XYVDfbXoqhTwwJ/ixfN4L5mWbJ7LKPMxT74ihD1WBP2RVbJ6p4VXBMIhq2+15d9O7H MGh080FHiKjU7YeiT+vvBueWKUnH+03gtA3YRyFw7oSA3eCso5MGFteRFpk2H0EpjPeC X5vkqxBjjHB/f5QYCmF4bQm7gerrctDFwU8PTMm8Sfih29jzTN1fZz1+KFxHcZvaLmo/ +YuXlyd5nqn0MlBCb8x/1dJ8CTFXO703vAeg/qNkcRjG/QvwKGeQ5rKMqOk3fbj8jXee 9x6xTfxjuVXraFVrGRIUWXoLCjtfY5xtvS+tWDu8CFwhrsuy6d/ZR/gK8Bn+yVo5xtXc mEbw== X-Gm-Message-State: AOAM531Q6K8ntN/4vrS59Gq2QWiyVJMk90SVpd2gXEh1Khzsh5cpOjgw Hgf+H1kbz9u6Qo3tWCqVKxhRbQ== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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