From nobody Sun Feb 8 00:11:35 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0827330317 for ; Fri, 17 Oct 2025 15:01:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760713321; cv=none; b=F+ootAH6dFEw1NzhOEkXrT1opNGOISv5an5I5B4IaK4uy8Ho1toZAOZuc49CF1NpxIMr0PMthbOnzdNzRe8Rpn357YMqXrX7sRtIEc9DSaN0VnTnLwbvQIlMmDNpvzjXpsdr2Kce/ZRFErX95Oz98HaTMCE6GpCE1Uz3mLcYJrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760713321; c=relaxed/simple; bh=km2whxGPM+a/D+/1UgPRs/9McTNUFDiXbwc6UAdplZ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FXrMdriuBmZr2gFW52g26THPSHr1R3amokVR9syFP4jyy3eIOqUIdsJPAIllqYOfB3m+rwQdk14s0hgBe4KaJuU9+dE7UXdtltLXOcagoEq/lpSOgpkLfKYRvGwM2azgq8b6JrodoML/jzXVIfxo8ajpymRZ3ODJRw37WkKmIdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=mChwSYc9; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="mChwSYc9" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 098DCC041F7; Fri, 17 Oct 2025 15:01:39 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5544D606DB; Fri, 17 Oct 2025 15:01:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8F092102F2363; Fri, 17 Oct 2025 17:01:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760713317; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=Xgi0RG1C3SH+AmnAQJ2k7QiHIPycUyOcGdZ0iSrESXc=; b=mChwSYc9H7qZSiAmz2nkjlcgyTAdD541xDc7UlvoOSHr25qKy8VumA5EYov6W3VLSxn/3u pJambaeKCoV6KqluJmLbM2Yd8ULaUg/nj+2JsMdSRMTFzEjBF6D34E8zn02ZupH0D7lOFs qk9Bza7TuBgc8Oyx38b4aRsUdI191D01Oufzvd1ZAY75T4+0vmZg7x6v50a3lSYaPn9Q1q dNStJszDEwxP/+bFrcYq6HNPY48WZFKJKp/SBi1RZwSPNw0LuxK/LTgQ60avuh2OBDBOcB YDbPLxGZBk++H5mwoczdpPAMlPU1I7tiLq14Xd5ZQG5raViU99NMRFAvzy6Cqw== From: =?utf-8?q?Beno=C3=AEt_Monin?= Date: Fri, 17 Oct 2025 16:59:32 +0200 Subject: [PATCH 1/3] dt-bindings: i2c: dw: Add Mobileye I2C controllers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251017-i2c-dw-v1-1-7b85b71c7a87@bootlin.com> References: <20251017-i2c-dw-v1-0-7b85b71c7a87@bootlin.com> In-Reply-To: <20251017-i2c-dw-v1-0-7b85b71c7a87@bootlin.com> To: Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jarkko Nikula , Mika Westerberg , Andy Shevchenko , Jan Dabros , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt Cc: Thomas Petazzoni , Gregory CLEMENT , =?utf-8?q?Th=C3=A9o_Lebrun?= , Tawfik Bayouk , Vladimir Kondratiev , Dmitry Guzman , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, =?utf-8?q?Beno=C3=AEt_Monin?= X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 Add compatible strings for the I2C controllers present in Mobileye Eyeq6Lplus and EyeQ7H SoCs. Signed-off-by: Beno=C3=AEt Monin --- Documentation/devicetree/bindings/i2c/snps,designware-i2c.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/i2c/snps,designware-i2c.yaml= b/Documentation/devicetree/bindings/i2c/snps,designware-i2c.yaml index d904191bb0c6e..6d63dc67f7bf0 100644 --- a/Documentation/devicetree/bindings/i2c/snps,designware-i2c.yaml +++ b/Documentation/devicetree/bindings/i2c/snps,designware-i2c.yaml @@ -36,6 +36,8 @@ properties: const: baikal,bt1-sys-i2c - items: - enum: + - mobileye,eyeq6lplus-i2c + - mobileye,eyeq7h-i2c - mscc,ocelot-i2c - sophgo,sg2044-i2c - thead,th1520-i2c --=20 2.51.0 From nobody Sun Feb 8 00:11:35 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C93D6335095 for ; Fri, 17 Oct 2025 15:02:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760713323; cv=none; b=f6fp+rYLQ4SovMrSy08bzbkjOsa1JSJEbdbxzcUCM/TYx/mWZKCMdqxwQgbHg4DZXaamlIub3vUmLvYfc2GI6Vm+cJb4I4GfruvZrxjeocevBPMRVvqB5nCJ7a+dAi6X2W2D3GCfwP+W1wUNjFasGaX1y4HpuIjfV9sgslKx/3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760713323; c=relaxed/simple; bh=CDYayh8Pxyj68cp2eLLP40bJ9vQMBBenjdICB9J5eb8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V80IIiUh1FVS86TXTaw6jMaQlr8AJKG8kchiKHfrz0L+JZuptCYhv2WgVEQd0lXsva8JaxsvWa0xsabm+pxSkkeBI4iVsCyTTgfR/HtocyckUWWiFBpiw01wDOxv9yWo7fDyrGymeROUlSCuQJMvGs3epzslOtLb3jAqH3XEQWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=IQoZu3gX; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="IQoZu3gX" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 2541EC041F8; Fri, 17 Oct 2025 15:01:41 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 70607606DB; Fri, 17 Oct 2025 15:02:00 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9CD8F102F233F; Fri, 17 Oct 2025 17:01:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760713319; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=lqaqDANIG/HsBzrXDtn2cFYQaaghRdRiFDBrzoTMERw=; b=IQoZu3gXUKP8Ss0bOQGB6yA3mdKlITAvNvEcsuVE9sq8P640SB/VBJA5g3TD4jtmPsDT41 HQGxjEEnB7V/CY3QRGNAgSxQ1jwdv5SiLzOHYakCWBqO+NYXHBdkcoMOQoLzQrSJOGugVN hfW8PI0WgXa6fvsMJaq4ndcJ5iwmiTYrGPw0EGjPXHwAYvLGGx0iBbD0GozFTWA9gEGpVM BHaSfe0NkzJGm9FVAnqwLh1RqcB1CMlthUIzK/03B8+pco4NejjkNd7cd2QLG0ZFZvP5TC DENm+kDeWSfPXNhBD4MosuKjLaWJLC6hdLVsIztCzQlFrYaxvRJEgjShz3DBQg== From: =?utf-8?q?Beno=C3=AEt_Monin?= Date: Fri, 17 Oct 2025 16:59:33 +0200 Subject: [PATCH 2/3] i2c: designware: Enable transfer with different target addresses Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251017-i2c-dw-v1-2-7b85b71c7a87@bootlin.com> References: <20251017-i2c-dw-v1-0-7b85b71c7a87@bootlin.com> In-Reply-To: <20251017-i2c-dw-v1-0-7b85b71c7a87@bootlin.com> To: Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jarkko Nikula , Mika Westerberg , Andy Shevchenko , Jan Dabros , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt Cc: Thomas Petazzoni , Gregory CLEMENT , =?utf-8?q?Th=C3=A9o_Lebrun?= , Tawfik Bayouk , Vladimir Kondratiev , Dmitry Guzman , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, =?utf-8?q?Beno=C3=AEt_Monin?= X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 When i2c_dw_xfer() is called with more than one message, it sets the target address according to the first message. If any of the following messages have a different target address, the transfer finishes with an error. Instead, if the next message has a different target address, wait until all previous messages are sent and the STOP condition is detected. This will complete the current part of the transfer. The next part is then handled by looping in i2c_dw_xfer(), calling i2c_dw_xfer_init() and i2c_dw_wait_transfer() until all messages of the transfer have been processed, or an error is detected. The RESTART bit is now set after the first message of each part of the transfer, instead of just after the very first message of the whole transfer. For each address change, i2c_dw_xfer_init() is called, which takes care of disabling the adapter before changing the target address register, then re-enabling it. Given that we cannot know the value of the I2C_DYNAMIC_TAR_UPDATE parameter, this is the only sure way to change the target address. Based on the work of Dmitry Guzman Signed-off-by: Beno=C3=AEt Monin --- drivers/i2c/busses/i2c-designware-master.c | 58 ++++++++++++++++----------= ---- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busse= s/i2c-designware-master.c index c7a72c28786c2..f9a180b145da8 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -436,6 +436,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) u8 *buf =3D dev->tx_buf; bool need_restart =3D false; unsigned int flr; + int first_idx =3D dev->msg_write_idx; =20 intr_mask =3D DW_IC_INTR_MASTER_MASK; =20 @@ -446,11 +447,11 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) * If target address has changed, we need to * reprogram the target address in the I2C * adapter when we are done with this transfer. + * This can be done after STOP_DET IRQ flag is raised. + * So, disable "TX FIFO empty" interrupt. */ if (msgs[dev->msg_write_idx].addr !=3D addr) { - dev_err(dev->dev, - "%s: invalid target address\n", __func__); - dev->msg_err =3D -EINVAL; + intr_mask &=3D ~DW_IC_INTR_TX_EMPTY; break; } =20 @@ -465,7 +466,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) * set restart bit between messages. */ if ((dev->master_cfg & DW_IC_CON_RESTART_EN) && - (dev->msg_write_idx > 0)) + (dev->msg_write_idx > first_idx)) need_restart =3D true; } =20 @@ -822,7 +823,6 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg ms= gs[], int num) break; } =20 - reinit_completion(&dev->cmd_complete); dev->msgs =3D msgs; dev->msgs_num =3D num; dev->cmd_err =3D 0; @@ -841,18 +841,33 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg = msgs[], int num) if (ret < 0) goto done; =20 - /* Start the transfers */ - i2c_dw_xfer_init(dev); + do { + reinit_completion(&dev->cmd_complete); =20 - /* Wait for tx to complete */ - ret =3D i2c_dw_wait_transfer(dev); - if (ret) { - dev_err(dev->dev, "controller timed out\n"); - /* i2c_dw_init_master() implicitly disables the adapter */ - i2c_recover_bus(&dev->adapter); - i2c_dw_init_master(dev); - goto done; - } + /* Start the transfers */ + i2c_dw_xfer_init(dev); + + /* Wait for tx to complete */ + ret =3D i2c_dw_wait_transfer(dev); + if (ret) { + dev_err(dev->dev, "controller timed out\n"); + /* i2c_dw_init_master() implicitly disables the adapter */ + i2c_recover_bus(&dev->adapter); + i2c_dw_init_master(dev); + goto done; + } + + if (dev->msg_err) { + ret =3D dev->msg_err; + goto done; + } + + /* We have an error */ + if (dev->cmd_err =3D=3D DW_IC_ERR_TX_ABRT) { + ret =3D i2c_dw_handle_tx_abort(dev); + goto done; + } + } while (dev->msg_write_idx < num); =20 /* * This happens rarely (~1:500) and is hard to reproduce. Debug trace @@ -874,23 +889,12 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg = msgs[], int num) */ __i2c_dw_disable_nowait(dev); =20 - if (dev->msg_err) { - ret =3D dev->msg_err; - goto done; - } - /* No error */ if (likely(!dev->cmd_err && !dev->status)) { ret =3D num; goto done; } =20 - /* We have an error */ - if (dev->cmd_err =3D=3D DW_IC_ERR_TX_ABRT) { - ret =3D i2c_dw_handle_tx_abort(dev); - goto done; - } - if (dev->status) dev_err(dev->dev, "transfer terminated early - interrupt latency too high?\n"); --=20 2.51.0 From nobody Sun Feb 8 00:11:35 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D220336EE2; Fri, 17 Oct 2025 15:02:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760713326; cv=none; b=iHm+cb1Cm+ibs6VboaKd3RHaccbjRgxI5HU0AJtC9gSZKiW+zMjMLfoGpCnMulTWjqRw4J2Fjnlzd0ZBcaIY4PjnblGSbJZcJ9WURzYt2gfOoqotF7SiDkJx1QT4WekC9jP6oqdTX+Lgq+k2PUrTDz4B6HjvSXYfTJxzxcNXPag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760713326; c=relaxed/simple; bh=CLWJhBu9K0krsl2W5BEPYqb1gmwqh8HxemHp6ZEorGM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UlVCx8Z7ohn5P3Z/H2GbZKSBXzucQxTkDESsF9V+boXisP1YglJkLUxCqOPjuzZErp23HuX1KSTkNt2SluLFgM1tgFVFgzHYqvefgD+/acg1rllejUJSuiLUHwfIMTz6ueLRWLjlw/5+lXrKP9/WPWiIC1tuVVgHyM6mRyOYuE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=V6v37aVg; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="V6v37aVg" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 9E24C1A1486; Fri, 17 Oct 2025 15:02:02 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 727DA606DB; Fri, 17 Oct 2025 15:02:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B1385102F2364; Fri, 17 Oct 2025 17:01:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760713321; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=OumetMRwPwRmXg7GTajWsCFnQn15iaJvKy3TjGNKXhI=; b=V6v37aVgwogvdcW9UXTbBHOAWJDdPJ7oWTOX6zn3PJRGeZE92VLrH5MicWn7An8n/yL65P lY4YM62v7/t8AEtLNlVTQj9rSJXIrXQlUFIJmM6/9zooVWqE2wZme/HErsqokpwIy0ml7c WA4LXvYoC7MrwKpIMAzIDdobV+CAUFZ1zWBevf9wTTvUAd4NkjCONMBx7t0Ua2LnyjdHu9 gy+h9df4mS/rXLNPlcWnCpsRIrVB8+75qZMXW8PzyWPu+fz1mIoZ3aY+V8ACnoluhLhE/q MYWzG1z0pWFWURGhD4238EUruBBewPu3kSqb4VR2c9asyVdkhVSeyUxI23K9pg== From: =?utf-8?q?Beno=C3=AEt_Monin?= Date: Fri, 17 Oct 2025 16:59:34 +0200 Subject: [PATCH 3/3] i2c: designware: Support of controller with IC_EMPTYFIFO_HOLD_MASTER disabled Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251017-i2c-dw-v1-3-7b85b71c7a87@bootlin.com> References: <20251017-i2c-dw-v1-0-7b85b71c7a87@bootlin.com> In-Reply-To: <20251017-i2c-dw-v1-0-7b85b71c7a87@bootlin.com> To: Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jarkko Nikula , Mika Westerberg , Andy Shevchenko , Jan Dabros , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt Cc: Thomas Petazzoni , Gregory CLEMENT , =?utf-8?q?Th=C3=A9o_Lebrun?= , Tawfik Bayouk , Vladimir Kondratiev , Dmitry Guzman , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, =?utf-8?q?Beno=C3=AEt_Monin?= X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 If IC_EMPTYFIFO_HOLD_MASTER_EN parameter is 0, "Stop" and "Repeated Start" bits in command register doesn't exist, thus it is impossible to send several consecutive write messages in a single hardware batch. The existing implementation worked with such configuration incorrectly: all consequent write messages joined into a single message without any Start/Stop or Repeated Start conditions. For example, the following command: i2ctransfer -y 0 w1@0x55 0x00 w1@0x55 0x01 does the same as i2ctransfer -y 0 w2@0x55 0x00 0x01 To fix it, for the controllers that behave this way, if the next message to the same slave device has the same direction as the previous one, it is sent to the controller only after the previous message is sent and STOP_DET IRQ flag is raised by the controller. This behavior is activated by compatible entries, because the state of the IC_EMPTYFIFO_HOLD_MASTER_EN parameter cannot be detected at runtime. Add the compatible entries of Mobileye SoCs needing the work-around and sort the entries alphabetically. There is another possible problem with this controller configuration: When the CPU is putting commands to the FIFO, this process must not be interrupted because if FIFO buffer gets empty, the controller finishes the I2C transaction and generates STOP condition on the bus. In a PREEMPT-RT kernel, interrupt handlers are by default executed in thread and may be interrupted, which can lead to breaking an I2C message by inserting an unwanted STOP. To ensure proper operation on realtime kernel, use IRQF_NO_THREAD flag when requesting IRQ. Based on the work of Dmitry Guzman Signed-off-by: Beno=C3=AEt Monin --- drivers/i2c/busses/i2c-designware-core.h | 1 + drivers/i2c/busses/i2c-designware-master.c | 45 +++++++++++++++++++++----= ---- drivers/i2c/busses/i2c-designware-platdrv.c | 6 ++-- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/= i2c-designware-core.h index 347843b4f5dd7..a31a8698e511a 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h @@ -311,6 +311,7 @@ struct dw_i2c_dev { #define ACCESS_NO_IRQ_SUSPEND BIT(1) #define ARBITRATION_SEMAPHORE BIT(2) #define ACCESS_POLLING BIT(3) +#define NO_EMPTYFIFO_HOLD_MASTER BIT(4) =20 #define MODEL_MSCC_OCELOT BIT(8) #define MODEL_BAIKAL_BT1 BIT(9) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busse= s/i2c-designware-master.c index f9a180b145da8..e5af0439ec832 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -443,18 +443,6 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) { u32 flags =3D msgs[dev->msg_write_idx].flags; =20 - /* - * If target address has changed, we need to - * reprogram the target address in the I2C - * adapter when we are done with this transfer. - * This can be done after STOP_DET IRQ flag is raised. - * So, disable "TX FIFO empty" interrupt. - */ - if (msgs[dev->msg_write_idx].addr !=3D addr) { - intr_mask &=3D ~DW_IC_INTR_TX_EMPTY; - break; - } - if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) { /* new i2c_msg */ buf =3D msgs[dev->msg_write_idx].buf; @@ -470,6 +458,25 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) need_restart =3D true; } =20 + /* + * If target address has changed, we need to + * reprogram the target address in the I2C + * adapter when we are done with this transfer. + * This can be done after STOP_DET IRQ flag is raised. + * So, disable "TX FIFO empty" interrupt. + * Also force a stop-then-start between two messages + * in the same direction if we need to restart on a + * adapter that does not handle restart. + */ + if (msgs[dev->msg_write_idx].addr !=3D addr || + ((need_restart && + dev->flags & NO_EMPTYFIFO_HOLD_MASTER && + ((msgs[dev->msg_write_idx].flags & I2C_M_RD) =3D=3D + (msgs[dev->msg_write_idx - 1].flags & I2C_M_RD))))) { + intr_mask &=3D ~DW_IC_INTR_TX_EMPTY; + break; + } + regmap_read(dev->map, DW_IC_TXFLR, &flr); tx_limit =3D dev->tx_fifo_depth - flr; =20 @@ -1062,6 +1069,20 @@ int i2c_dw_probe_master(struct dw_i2c_dev *dev) irq_flags =3D IRQF_SHARED | IRQF_COND_SUSPEND; } =20 + /* + * The first writing to TX FIFO buffer causes transmission start. If + * IC_EMPTYFIFO_HOLD_MASTER_EN is not set, when TX FIFO gets empty, I2C + * controller finishes the transaction. If writing to FIFO is + * interrupted, FIFO can get empty and the transaction will be finished + * prematurely. FIFO buffer is filled in IRQ handler, but in PREEMPT_RT + * kernel IRQ handler by default is executed in thread that can be + * preempted with another higher priority thread or an interrupt. So, + * IRQF_NO_THREAD flag is required in order to prevent any preemption + * during filling the FIFO buffer and possible data lost. + */ + if (dev->flags & NO_EMPTYFIFO_HOLD_MASTER) + irq_flags |=3D IRQF_NO_THREAD; + ret =3D i2c_dw_acquire_lock(dev); if (ret) return ret; diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/buss= es/i2c-designware-platdrv.c index 34d881572351c..5e459175dcdb2 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -345,9 +345,11 @@ static void dw_i2c_plat_remove(struct platform_device = *pdev) } =20 static const struct of_device_id dw_i2c_of_match[] =3D { - { .compatible =3D "snps,designware-i2c", }, - { .compatible =3D "mscc,ocelot-i2c", .data =3D (void *)MODEL_MSCC_OCELOT = }, { .compatible =3D "baikal,bt1-sys-i2c", .data =3D (void *)MODEL_BAIKAL_BT= 1 }, + { .compatible =3D "mobileye,eyeq6lplus-i2c", .data =3D (void *)NO_EMPTYFI= FO_HOLD_MASTER }, + { .compatible =3D "mobileye,eyeq7h-i2c", .data =3D (void *)NO_EMPTYFIFO_H= OLD_MASTER }, + { .compatible =3D "mscc,ocelot-i2c", .data =3D (void *)MODEL_MSCC_OCELOT = }, + { .compatible =3D "snps,designware-i2c", }, {} }; MODULE_DEVICE_TABLE(of, dw_i2c_of_match); --=20 2.51.0