Skip to contentSkip to conversation

i2c: designware: add support for pinctrl for recovery

PATCH Superseded Yann Sionneau 2 participants 3 messages Aug 11, 2023 – Aug 16, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: designware: add support for pinctrl for recovery

From: Yann Sionneau <[email protected]>

Currently if the SoC needs pinctrl to switch the scl and sda from hw function to gpio function, the recovery won't work.

scl-gpio = <>;
sda-gpio = <>;

Are not enough for some SoCs to have a working recovery. Some need:

scl-gpio = <>;
sda-gpio = <>;
pinctrl-names = "default", "recovery";
pinctrl-0 = <&i2c_pins_hw>;
pinctrl-1 = <&i2c_pins_gpio>;

The driver was not filling rinfo->pinctrl with the device node pinctrl data which is needed by generic recovery code.

---
 drivers/i2c/busses/i2c-designware-master.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/i2c/busses/i2c-designware-master.c +7 -0
index bee296cd74e6..b55c19b2515a 100644
@@ -20,6 +20,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <linux/reset.h>
+#include <linux/pinctrl/consumer.h>
 
 #include "i2c-designware-core.h"
 
@@ -841,6 +842,12 @@ static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev)
 		return PTR_ERR(gpio);
 	rinfo->sda_gpiod = gpio;
 
+	rinfo->pinctrl = devm_pinctrl_get(dev->dev);
+	if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
+		rinfo->pinctrl = NULL;
+		dev_info(dev->dev, "can't get pinctrl, bus recovery might not work\n");
+	}
+
 	rinfo->recover_bus = i2c_generic_scl_recovery;
 	rinfo->prepare_recovery = i2c_dw_prepare_recovery;
 	rinfo->unprepare_recovery = i2c_dw_unprepare_recovery;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Yann Sionneau

From: Yann Sionneau <[email protected]>

Currently if the SoC needs pinctrl to switch the scl and sda

SCL
SDA

Quoted 1 line

from hw function to gpio function, the recovery won't work.

from the I2C

GPIO

Quoted 14 lines

scl-gpio = <>;
sda-gpio = <>;

Are not enough for some SoCs to have a working recovery. Some need:

scl-gpio = <>;
sda-gpio = <>;
pinctrl-names = "default", "recovery";
pinctrl-0 = <&i2c_pins_hw>;
pinctrl-1 = <&i2c_pins_gpio>;

The driver was not filling rinfo->pinctrl with the device node pinctrl data which is needed by generic recovery code.

...

Quoted 4 lines

#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <linux/reset.h>
+#include <linux/pinctrl/consumer.h>

Keep this in order.

...

drivers/i2c/busses/i2c-designware-master.c static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev) · line 846

Quoted 2 lines
drivers/i2c/busses/i2c-designware-master.c +2 -0
+	rinfo->pinctrl = devm_pinctrl_get(dev->dev);
+	if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {

It's not possible to have it NULL, why a dead code?

Quoted 3 lines
drivers/i2c/busses/i2c-designware-master.c +3 -0
+		rinfo->pinctrl = NULL;
+		dev_info(dev->dev, "can't get pinctrl, bus recovery might not work\n");
+	}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

Le 11/08/2023 à 16:36, Andy Shevchenko a écrit :

Quoted 6 lines · Yann Sionneau
Quoted 3 lines

From: Yann Sionneau <[email protected]>

Currently if the SoC needs pinctrl to switch the scl and sda

SCL
SDA

ack

Quoted 5 lines
Quoted 2 lines

from hw function to gpio function, the recovery won't work.

from the I2C

GPIO

ack

Quoted 5 lines
Quoted 4 lines

#include <linux/pm_runtime.h>
#include <linux/regmap.h>
#include <linux/reset.h>
+#include <linux/pinctrl/consumer.h>

Keep this in order.

Ok

Quoted 6 lines

...

drivers/i2c/busses/i2c-designware-master.c static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev) · line 846

Quoted 2 lines
drivers/i2c/busses/i2c-designware-master.c +2 -0
+	rinfo->pinctrl = devm_pinctrl_get(dev->dev);
+	if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {

It's not possible to have it NULL, why a dead code?

Woops, I thought NULL was possible, you are right: it's impossible.

I will also add handling of -EPROBE_DEFER error.

Thanks for the review.

Regards,

Signature · 1 line
Yann