From patchwork Thu Jul 6 12:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TcOlbnMgUnVsbGfDpXJk?= X-Patchwork-Id: 13303687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17020EB64D9 for ; Thu, 6 Jul 2023 12:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=NTILvMtgSgDl53gncYsbouRqOSxwMBNVgKPSk0CZ4/M=; b=iPeW/CiIN1xelv YOJrWxUP7vLnykB1gz1cc2fcnS/4uPpYUGsjrTTe7zKq6bmLWlkO6Y2zMIO1GZi7FTFa0mJwt/vz7 gg/J6f4eL8bLNPCXGA+6vq+OJwuDAcSQGjUlFXtBzbRZgKyl3HicTxRBAXJWwh3uqUwEHf26x9viG WMzzXcQ/14YN7gBdha+NA/k/XE7ltqD0ldsVw17/d8IAmrovVYkBTN1FeGG6Tv/nAXwlkTUIAQ/ja fWU45NHy975XTRX/o/8ZXm600nZ3526j9d4aY1kATPzpeuI4Ffm41exucwq1bUGOerjsOBi9h1W64 xgFgBpeiwXq1QbDtxmEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHOYn-001ijt-00; Thu, 06 Jul 2023 12:58:13 +0000 Received: from unicorn.mansr.com ([81.2.72.234]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qHOYk-001ijS-1S for linux-arm-kernel@lists.infradead.org; Thu, 06 Jul 2023 12:58:12 +0000 Received: from raven.mansr.com (raven.mansr.com [IPv6:2001:8b0:ca0d:1::3]) by unicorn.mansr.com (Postfix) with ESMTPS id DE08515360; Thu, 6 Jul 2023 13:58:03 +0100 (BST) Received: by raven.mansr.com (Postfix, from userid 51770) id CF8DB219FC1; Thu, 6 Jul 2023 13:58:03 +0100 (BST) From: Mans Rullgard To: Oleksij Rempel , Pengutronix Kernel Team Cc: Andi Shyti , Shawn Guo , Sascha Hauer , Fabio Estevam , NXP Linux Team , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] i2c: imx: add support for I2C_M_STOP flag Date: Thu, 6 Jul 2023 13:57:29 +0100 Message-ID: <20230706125729.17335-1-mans@mansr.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230706_055810_649211_C3DA514D X-CRM114-Status: GOOD ( 14.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for the I2C_M_STOP flag to the i2c-imx driver. This allows devices requiring a stop between messages to work with this controller. Signed-off-by: Mans Rullgard --- drivers/i2c/busses/i2c-imx.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 42189a5f2905..f59d086688ff 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -1262,10 +1262,17 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter, /* read/write data */ for (i = 0; i < num; i++) { - if (i == num - 1) - is_lastmsg = true; + if (is_lastmsg) { + /* previous message had I2C_M_STOP flag set */ + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + temp |= I2CR_MSTA; + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + result = i2c_imx_bus_busy(i2c_imx, 1, atomic); + if (result) + goto fail0; + } - if (i) { + if (i && !is_lastmsg) { dev_dbg(&i2c_imx->adapter.dev, "<%s> repeated start\n", __func__); temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); @@ -1275,6 +1282,10 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter, if (result) goto fail0; } + + if (i == num - 1 || (msgs[i].flags & I2C_M_STOP)) + is_lastmsg = true; + dev_dbg(&i2c_imx->adapter.dev, "<%s> transfer message: %d\n", __func__, i); /* write/read data */ @@ -1304,6 +1315,13 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter, result = i2c_imx_dma_write(i2c_imx, &msgs[i]); else result = i2c_imx_write(i2c_imx, &msgs[i], atomic); + + if (msgs[i].flags & I2C_M_STOP) { + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + temp &= ~I2CR_MSTA; + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + i2c_imx_bus_busy(i2c_imx, 0, atomic); + } } if (result) goto fail0; @@ -1425,7 +1443,7 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, static u32 i2c_imx_func(struct i2c_adapter *adapter) { - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL + return I2C_FUNC_I2C | I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_READ_BLOCK_DATA; }