Skip to contentSkip to conversation

i2c: Set i2c pinctrl recovery info from it's device pinctrl

PATCH Superseded Hanna Hawa 2 participants 5 messages Dec 21, 2022 – Dec 28, 2022

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Hanna Hawa

author
#0 lore raw

v4 cover i2c: Set i2c pinctrl recovery info from it's device pinctrl

This series include two changes:
1. Adding new API to get the device pinctrl information when it's initialized before device probed.
2. Make the i2c init recovery to get the device pins if it's not initialized by the driver from the device pins.

Change Log v3->v4:
- Split the change into 2 commits
- Add cover letter and remove change log from commit message
- Fix compilation failure when CONFIG_PINCTRL is not defined

Change Log v2->v3:
- Add API to get the device pinctrl
- Make the i2c init recovery to get the device pins

Change Log v1->v2:
- set the rinfo->pinctrl to dev->pins->p instead calling devm_pinctrl_get()

Hanna Hawa (2):
pinctrl: Add an API to get the pinctrl pins if initialized
i2c: Set i2c pinctrl recovery info from it's device pinctrl

 drivers/i2c/i2c-core-base.c     |  6 +++++-
 include/linux/pinctrl/devinfo.h | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
2.38.1
author
#1 lore raw

PATCH v4 1/2 pinctrl: Add an API to get the pinctrl pins if initialized

Add an API to get the pinctrl pins if it was initialized before driver probed. This API will be used in I2C core to get the device pinctrl information for recovery state change.

---
 include/linux/pinctrl/devinfo.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/linux/pinctrl/devinfo.h +14 -0
index a48ff69acddd..83eef2ac8cd6 100644
@@ -17,6 +17,7 @@
 #ifdef CONFIG_PINCTRL
 
 /* The device core acts as a consumer toward pinctrl */
+#include <linux/device.h>
 #include <linux/pinctrl/consumer.h>
 
 /**
@@ -40,6 +41,14 @@ struct dev_pin_info {
 extern int pinctrl_bind_pins(struct device *dev);
 extern int pinctrl_init_done(struct device *dev);
 
+static inline struct pinctrl *dev_pinctrl(struct device *dev)
+{
+	if (!dev->pins)
+		return NULL;
+
+	return dev->pins->p;
+}
+
 #else
 
 struct device;
@@ -56,5 +65,10 @@ static inline int pinctrl_init_done(struct device *dev)
 	return 0;
 }
 
+static inline struct pinctrl *dev_pinctrl(struct device *dev)
+{
+	return NULL;
+}
+
 #endif /* CONFIG_PINCTRL */
 #endif /* PINCTRL_DEVINFO_H */
Signature · 1 line
2.38.1
Reviewed-by on v4 1/2
#2 lore raw

Re: [PATCH v4 1/2] pinctrl: Add an API to get the pinctrl pins if initialized

Quoted 3 lines · Hanna Hawa

Add an API to get the pinctrl pins if it was initialized before driver probed. This API will be used in I2C core to get the device pinctrl information for recovery state change.

...

Quoted 3 lines

/* The device core acts as a consumer toward pinctrl */

+#include <linux/device.h>

It's slightly misplaced. The comment above is for the below inclusion.

Quoted 1 line

#include <linux/pinctrl/consumer.h>

Can we make it

----8<----
#include <linux/device.h>

/* The device core acts as a consumer toward pinctrl */ #include <linux/pinctrl/consumer.h>
----8<----

?

With this addressed,

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#3 lore raw

PATCH v4 2/2 i2c: Set i2c pinctrl recovery info from it's device pinctrl

In reply to Hanna Hawa

Currently the i2c subsystem rely on the controller device tree to initialize the pinctrl recovery information, part of the drivers does not set this field (rinfo->pinctrl), for example i2c designware driver.

The pins information is saved part of the device structure before probe and it's done on pinctrl_bind_pins().

Make the i2c init recovery to get the device pins if it's not initialized by the driver from the device pins.

---
 drivers/i2c/i2c-core-base.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/i2c/i2c-core-base.c +5 -1
index 7539b0740351..8c5f76c43dc8 100644
@@ -34,6 +34,7 @@
 #include <linux/of.h>
 #include <linux/of_irq.h>
 #include <linux/pinctrl/consumer.h>
+#include <linux/pinctrl/devinfo.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm_wakeirq.h>
@@ -282,7 +283,10 @@ static void i2c_gpio_init_pinctrl_recovery(struct i2c_adapter *adap)
 {
 	struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
 	struct device *dev = &adap->dev;
-	struct pinctrl *p = bri->pinctrl;
+	struct pinctrl *p;
+
+	bri->pinctrl = bri->pinctrl ?: dev_pinctrl(dev->parent);
+	p = bri->pinctrl;
 
 	/*
 	 * we can't change states without pinctrl, so remove the states if
Signature · 1 line
2.38.1
Reviewed-by on v4 2/2
#4 lore raw
Quoted 3 lines · Hanna Hawa

Currently the i2c subsystem rely on the controller device tree to initialize the pinctrl recovery information, part of the drivers does not set this field (rinfo->pinctrl), for example i2c designware driver.

DesignWare

Quoted 5 lines

The pins information is saved part of the device structure before probe and it's done on pinctrl_bind_pins().

Make the i2c init recovery to get the device pins if it's not initialized by the driver from the device pins.

...

drivers/i2c/i2c-core-base.c static void i2c_gpio_init_pinctrl_recovery(struct i2c_adapter *adap) · line 289

Quoted 5 lines
drivers/i2c/i2c-core-base.c +4 -1
-	struct pinctrl *p = bri->pinctrl;
+	struct pinctrl *p;
+
+	bri->pinctrl = bri->pinctrl ?: dev_pinctrl(dev->parent);
+	p = bri->pinctrl;

What about

	struct pinctrl *p = bri->pinctrl ?: dev_pinctrl(dev->parent);

	bri->pinctrl = p;

?

Seems like one line of code less.

Either way,

Signature · 2 lines
With Best Regards,
Andy Shevchenko