lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231218-i2c-imx-recovery-v1-1-f69fa85b228c@ew.tq-group.com>
Date: Mon, 18 Dec 2023 18:06:12 +0100
From: Gregor Herburger <gregor.herburger@...tq-group.com>
To: Oleksij Rempel <o.rempel@...gutronix.de>, 
 Pengutronix Kernel Team <kernel@...gutronix.de>, 
 Andi Shyti <andi.shyti@...nel.org>, Shawn Guo <shawnguo@...nel.org>, 
 Sascha Hauer <s.hauer@...gutronix.de>, Fabio Estevam <festevam@...il.com>, 
 NXP Linux Team <linux-imx@....com>
Cc: linux-i2c@...r.kernel.org, linux-arm-kernel@...ts.infradead.org, 
 linux-kernel@...r.kernel.org, linux@...tq-group.com, 
 gregor.herburger@...tq-group.com
Subject: [PATCH] i2c: i2c-imx: allow bus recovery on non-muxable pads

Currently the i2c-imx driver assumes that for bus recovery the i2c pins
can be reconfigured as gpio via pinctrl.

But bus recovery can also be done with a gpio electrically connected to
i2c scl.

Modify i2c_imx_init_recovery_info to allow bus recovery on platforms
without pinctrl. In this case only use scl-gpio and
i2c_generic_scl_recovery.

Signed-off-by: Gregor Herburger <gregor.herburger@...tq-group.com>
---
 drivers/i2c/busses/i2c-imx.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 1775a79aeba2..7d71accb031b 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1388,20 +1388,23 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
 	struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
 
 	i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
-	if (!i2c_imx->pinctrl) {
-		dev_info(&pdev->dev, "pinctrl unavailable, bus recovery not supported\n");
-		return 0;
-	}
+
+	if (PTR_ERR(i2c_imx->pinctrl) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
 	if (IS_ERR(i2c_imx->pinctrl)) {
-		dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
-		return PTR_ERR(i2c_imx->pinctrl);
+		i2c_imx->pinctrl = NULL;
+		dev_info(&pdev->dev, "can't get pinctrl, trying non-pinctrl gpio recovery.\n");
 	}
 
-	i2c_imx->pinctrl_pins_default = pinctrl_lookup_state(i2c_imx->pinctrl,
-			PINCTRL_STATE_DEFAULT);
-	i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl,
-			"gpio");
-	rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN);
+	if (i2c_imx->pinctrl) {
+		i2c_imx->pinctrl_pins_default = pinctrl_lookup_state(i2c_imx->pinctrl,
+				PINCTRL_STATE_DEFAULT);
+		i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl,
+				"gpio");
+	}
+
+	rinfo->sda_gpiod = devm_gpiod_get_optional(&pdev->dev, "sda", GPIOD_IN);
 	rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN);
 
 	if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER ||
@@ -1415,11 +1418,15 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
 		return 0;
 	}
 
-	dev_dbg(&pdev->dev, "using scl%s for recovery\n",
+	if (i2c_imx->pinctrl_pins_default && i2c_imx->pinctrl_pins_gpio) {
+		rinfo->prepare_recovery = i2c_imx_prepare_recovery;
+		rinfo->unprepare_recovery = i2c_imx_unprepare_recovery;
+	}
+
+	dev_dbg(&pdev->dev, "using %sscl%s for recovery\n",
+		i2c_imx->pinctrl ? "pinctrl " : "",
 		rinfo->sda_gpiod ? ",sda" : "");
 
-	rinfo->prepare_recovery = i2c_imx_prepare_recovery;
-	rinfo->unprepare_recovery = i2c_imx_unprepare_recovery;
 	rinfo->recover_bus = i2c_generic_scl_recovery;
 	i2c_imx->adapter.bus_recovery_info = rinfo;
 

---
base-commit: ceb2fe0d438644e1de06b9a6468a1fb8e2199c70
change-id: 20231218-i2c-imx-recovery-6da66f0381df

Best regards,
-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ