Skip to contentSkip to conversation

pinctrl: don't fall back to pinctrl_select_state_simple()

PATCH In review Michael Walle 4 participants 14 messages Jan 18, 2023 – Jan 27, 2023 Pin control

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 pinctrl: don't fall back to pinctrl_select_state_simple()

If CONFIG_PINCTRL_FULL is enabled, never fall back to the simple implementation. pinctrl_select_state() is called for each device and it is expected to fail. A fallback to the simple imeplementation doesn't make much sense.

To keep the return code consistent, we need to change the -EINVAL (which was ignored before) to -ENOSYS.

---
The real underlying problem is that the pinctrl_select_state_simple() doesn't really work before relocation. This implementation calls uclass_get_device() which will try to probe the pinctrl, but that device might not be ready yet, i.e. in my case, it is an MFD and it needs its parent. For each device in the devicetree, there will be a device_probe(pinctrl) attempt and if that device has some kind of private or platform data, it will eat away the early memory, because there is no free.

I'm not really sure how that could be fixed. But still, if there is a full implementation, it shouldn't fall back to the simple one.

---
 drivers/pinctrl/pinctrl-uclass.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/pinctrl/pinctrl-uclass.c +5 -10
index ce2d5ddf6d..419ef5f52f 100644
@@ -71,13 +71,13 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
 		 */
 		state = dectoul(statename, &end);
 		if (*end)
-			return -EINVAL;
+			return -ENOSYS;
 	}
 
 	snprintf(propname, sizeof(propname), "pinctrl-%d", state);
 	list = dev_read_prop(dev, propname, &size);
 	if (!list)
-		return -EINVAL;
+		return -ENOSYS;
 
 	size /= sizeof(*list);
 	for (i = 0; i < size; i++) {
@@ -162,11 +162,6 @@ U_BOOT_DRIVER(pinconfig_generic) = {
 };
 
 #else
-static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
-{
-	return -ENODEV;
-}
-
 static int pinconfig_post_bind(struct udevice *dev)
 {
 	return 0;
@@ -317,10 +312,10 @@ int pinctrl_select_state(struct udevice *dev, const char *statename)
 	 * Try full-implemented pinctrl first.
 	 * If it fails or is not implemented, try simple one.
 	 */
-	if (pinctrl_select_state_full(dev, statename))
-		return pinctrl_select_state_simple(dev);
+	if (CONFIG_IS_ENABLED(PINCTRL_FULL))
+		return pinctrl_select_state_full(dev, statename);
 
-	return 0;
+	return pinctrl_select_state_simple(dev);
 }
 
 int pinctrl_request(struct udevice *dev, int func, int flags)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/3 pinctrl: get rid of some ifdeffery

Don't define an empty version for pinconfig_post_bind(). Just guard the call and let the linker garbage collection do the rest. This way, we also don't have to do any guesswork.

---
 drivers/pinctrl/pinctrl-uclass.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/pinctrl/pinctrl-uclass.c +5 -12
index 419ef5f52f..e6cd0889b0 100644
@@ -20,7 +20,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if CONFIG_IS_ENABLED(PINCTRL_FULL)
 /**
  * pinctrl_config_one() - apply pinctrl settings for a single node
  *
@@ -148,6 +147,7 @@ static int pinconfig_post_bind(struct udevice *dev)
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(PINCTRL_FULL)
 UCLASS_DRIVER(pinconfig) = {
 	.id = UCLASS_PINCONFIG,
 #if CONFIG_IS_ENABLED(PINCONF_RECURSIVE)
@@ -160,12 +160,6 @@ U_BOOT_DRIVER(pinconfig_generic) = {
 	.name = "pinconfig",
 	.id = UCLASS_PINCONFIG,
 };
-
-#else
-static int pinconfig_post_bind(struct udevice *dev)
-{
-	return 0;
-}
 #endif
 
 static int
@@ -411,12 +405,11 @@ static int __maybe_unused pinctrl_post_bind(struct udevice *dev)
 	}
 
 	/*
-	 * If set_state callback is set, we assume this pinctrl driver is the
-	 * full implementation.  In this case, its child nodes should be bound
-	 * so that peripheral devices can easily search in parent devices
-	 * during later DT-parsing.
+	 * If the pinctrl driver has the full implementation, its child nodes
+	 * should be bound so that peripheral devices can easily search in
+	 * parent devices during later DT-parsing.
 	 */
-	if (ops->set_state)
+	if (CONFIG_IS_ENABLED(PINCTRL_FULL))
 		return pinconfig_post_bind(dev);
 
 	return 0;
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH 2/3] pinctrl: get rid of some ifdeffery

On 1/18/23 13:12, Michael Walle wrote:

[...]

Quoted 5 lines
drivers/pinctrl/pinctrl-uclass.c +0 -1
@@ -411,12 +405,11 @@ static int __maybe_unused pinctrl_post_bind(struct udevice *dev)
  	}
 
  	/*
-	 * If set_state callback is set, we assume this pinctrl driver is the

drivers/pinctrl/pinctrl-uclass.c static int __maybe_unused pinctrl_post_bind(struct udevice *dev) · line 413

Quoted 10 lines
drivers/pinctrl/pinctrl-uclass.c +4 -4
-	 * full implementation.  In this case, its child nodes should be bound
-	 * so that peripheral devices can easily search in parent devices
-	 * during later DT-parsing.
+	 * If the pinctrl driver has the full implementation, its child nodes
+	 * should be bound so that peripheral devices can easily search in
+	 * parent devices during later DT-parsing.
  	 */
-	if (ops->set_state)
+	if (CONFIG_IS_ENABLED(PINCTRL_FULL))
  		return pinconfig_post_bind(dev);

Is it correct to drop the ops->set_state non-NULL check ?

#3 lore raw

Re: [PATCH 2/3] pinctrl: get rid of some ifdeffery

Am 2023-01-18 13:18, schrieb Marek Vasut:

Quoted 16 lines · Michael Walle

[...]

Quoted 12 lines
(quoted diff) +0 -1
@@ -411,12 +405,11 @@ static int __maybe_unused 
 pinctrl_post_bind(struct udevice *dev)
  	}
    	/*
-	 * If set_state callback is set, we assume this pinctrl driver is 

the

(quoted diff) +0 -1
-	 * full implementation.  In this case, its child nodes should be 

bound

drivers/pinctrl/pinctrl-uclass.c +1 -2
-	 * so that peripheral devices can easily search in parent devices
-	 * during later DT-parsing.
+	 * If the pinctrl driver has the full implementation, its child 

nodes

Quoted 8 lines

drivers/pinctrl/pinctrl-uclass.c static int __maybe_unused pinctrl_post_bind(struct udevice *dev) · line 413

Quoted 6 lines
drivers/pinctrl/pinctrl-uclass.c +3 -1
+	 * should be bound so that peripheral devices can easily search in
+	 * parent devices during later DT-parsing.
  	 */
-	if (ops->set_state)
+	if (CONFIG_IS_ENABLED(PINCTRL_FULL))
  		return pinconfig_post_bind(dev);

Is it correct to drop the ops->set_state non-NULL check ?

See include/dm/pinctrl.h. set_state() is mandatory. Although, that seems to be wrong for the simple implementation.

-michael

#4 lore raw

Re: [PATCH 2/3] pinctrl: get rid of some ifdeffery

Quoted 26 lines · Michael Walle

Am 2023-01-18 13:18, schrieb Marek Vasut:

Quoted 16 lines · Michael Walle

[...]

Quoted 12 lines
(quoted diff) +0 -1
@@ -411,12 +405,11 @@ static int __maybe_unused 
 pinctrl_post_bind(struct udevice *dev)
       }
         /*
-     * If set_state callback is set, we assume this pinctrl driver 

is the
-     * full implementation.  In this case, its child nodes should be bound
-     * so that peripheral devices can easily search in parent devices -     * during later DT-parsing.
+     * If the pinctrl driver has the full implementation, its child nodes

Quoted 8 lines
Quoted 6 lines

+     * should be bound so that peripheral devices can easily search in +     * parent devices during later DT-parsing.
       */
-    if (ops->set_state)
+    if (CONFIG_IS_ENABLED(PINCTRL_FULL))
          return pinconfig_post_bind(dev);

Is it correct to drop the ops->set_state non-NULL check ?

Quoted 2 lines

See include/dm/pinctrl.h. set_state() is mandatory. Although, that seems to be wrong for the simple implementation.

Could that be fixed for the simple case ? I think that should be easy to do, right ?

#5 lore raw

Re: [PATCH 2/3] pinctrl: get rid of some ifdeffery

Am 2023-01-18 14:08, schrieb Marek Vasut:

Quoted 29 lines · Michael Walle
Quoted 28 lines

Am 2023-01-18 13:18, schrieb Marek Vasut:

Quoted 26 lines · Michael Walle

[...]

Quoted 12 lines
(quoted diff) +0 -1
@@ -411,12 +405,11 @@ static int __maybe_unused 
 pinctrl_post_bind(struct udevice *dev)
       }
         /*
-     * If set_state callback is set, we assume this pinctrl driver 

is the
-     * full implementation.  In this case, its child nodes should be bound
-     * so that peripheral devices can easily search in parent devices
-     * during later DT-parsing.
+     * If the pinctrl driver has the full implementation, its child

Quoted 8 lines

nodes
+     * should be bound so that peripheral devices can easily search in
+     * parent devices during later DT-parsing.
       */
-    if (ops->set_state)
+    if (CONFIG_IS_ENABLED(PINCTRL_FULL))
          return pinconfig_post_bind(dev);

Is it correct to drop the ops->set_state non-NULL check ?

Quoted 5 lines
Quoted 2 lines

See include/dm/pinctrl.h. set_state() is mandatory. Although, that seems to be wrong for the simple implementation.

Could that be fixed for the simple case ? I think that should be easy to do, right ?

You mean a documentation fix?

-michael

Reviewed-by
#6 lore raw

Re: [PATCH 2/3] pinctrl: get rid of some ifdeffery

Quoted 29 lines · Michael Walle

Am 2023-01-18 14:08, schrieb Marek Vasut:

Quoted 28 lines · Michael Walle
Quoted 27 lines

Am 2023-01-18 13:18, schrieb Marek Vasut:

Quoted 25 lines · Michael Walle

[...]

Quoted 11 lines
(quoted diff) +0 -1
@@ -411,12 +405,11 @@ static int __maybe_unused 
 pinctrl_post_bind(struct udevice *dev)
       }
         /*
-     * If set_state callback is set, we assume this pinctrl driver 

is the
-     * full implementation.  In this case, its child nodes should be bound
-     * so that peripheral devices can easily search in parent devices -     * during later DT-parsing.
+     * If the pinctrl driver has the full implementation, its

Quoted 8 lines

child nodes
+     * should be bound so that peripheral devices can easily search in
+     * parent devices during later DT-parsing.
       */
-    if (ops->set_state)
+    if (CONFIG_IS_ENABLED(PINCTRL_FULL))
          return pinconfig_post_bind(dev);

Is it correct to drop the ops->set_state non-NULL check ?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

See include/dm/pinctrl.h. set_state() is mandatory. Although, that seems to be wrong for the simple implementation.

Could that be fixed for the simple case ? I think that should be easy to do, right ?

You mean a documentation fix?

Reading the original comment one more time, no, I think this patch is fine as is, sorry for the noise.

#8 lore raw

PATCH 3/3 pinctrl: fix docstring

In reply to Michael Walle

Fix the copy and paste error.

---
 drivers/pinctrl/pinctrl-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-uclass.c +1 -1
index e6cd0889b0..23a1504716 100644
@@ -382,7 +382,7 @@ int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf,
 }
 
 /**
- * pinconfig_post_bind() - post binding for PINCTRL uclass
+ * pinctrl_post_bind() - post binding for PINCTRL uclass
  * Recursively bind child nodes as pinconfig devices in case of full pinctrl.
  *
  * @dev: pinctrl device
Signature · 1 line
2.30.2
Reviewed-by on v1 1/3
#11 lore raw
In reply to Michael Walle
Quoted 9 lines · Michael Walle

If CONFIG_PINCTRL_FULL is enabled, never fall back to the simple implementation. pinctrl_select_state() is called for each device and it is expected to fail. A fallback to the simple imeplementation doesn't make much sense.

To keep the return code consistent, we need to change the -EINVAL (which was ignored before) to -ENOSYS.

Reviewed-by
#12 lore raw
Quoted 7 lines · Marek Vasut
Quoted 5 lines · Michael Walle

If CONFIG_PINCTRL_FULL is enabled, never fall back to the simple implementation. pinctrl_select_state() is called for each device and it is expected to fail. A fallback to the simple imeplementation doesn't make much sense.

Quoted 6 lines
Quoted 4 lines

To keep the return code consistent, we need to change the -EINVAL (which was ignored before) to -ENOSYS.

#13 lore raw
In reply to Michael Walle
Quoted 11 lines · Michael Walle

If CONFIG_PINCTRL_FULL is enabled, never fall back to the simple implementation. pinctrl_select_state() is called for each device and it is expected to fail. A fallback to the simple imeplementation doesn't make much sense.

To keep the return code consistent, we need to change the -EINVAL (which was ignored before) to -ENOSYS.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom