Skip to contentSkip to conversation

pinctrl: support selecting states from command line

PATCH Applied Ahmad Fatoum 2 participants 2 messages Oct 27, 2025 – Oct 28, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: support selecting states from command line

This can be useful for debugging to exercise pinctrl for nodes that have no driver yet. Example:

setenv adc-joystick.of.pinctrl_state=default

---
 drivers/base/driver.c     |  4 ++
 drivers/pinctrl/Kconfig   |  4 ++
 drivers/pinctrl/pinctrl.c | 92 +++++++++++++++++++++++++++++++++++++++
 include/param.h           |  2 +
 include/pinctrl.h         | 10 +++++
 lib/parameter.c           |  6 ++-
 6 files changed, 116 insertions(+), 2 deletions(-)
drivers/base/driver.c +4 -0
index 61118385f1df..33d9e2bcde5a 100644
@@ -268,6 +268,8 @@ int register_device(struct device *new_device)
 
 	bobject_init(&new_device->bobject);
 
+	of_pinctrl_register_consumer(new_device, new_device->device_node);
+
 	if (new_device->bus) {
 		if (!new_device->parent)
 			new_device->parent = &new_device->bus->dev;
@@ -298,6 +300,8 @@ int unregister_device(struct device *old_dev)
 
 	bobject_del(&old_dev->bobject);
 
+	of_pinctrl_unregister_consumer(old_dev);
+
 	if (old_dev->driver)
 		device_remove(old_dev);
 
drivers/pinctrl/Kconfig +4 -0
index 72ca79aa9880..1d237db106ba 100644
@@ -10,6 +10,10 @@ config PINCTRL
 	  from the devicetree. Legacy drivers here may not need this core
 	  support but instead provide their own SoC specific APIs
 
+config PINCTRL_STATE_PARAM
+	bool "pinctrl state control via device parameters"
+	depends on PARAMETER && PINCTRL
+
 # The following drivers are needed even without PINCTRL because
 # the either have a legacy iomux interface or also register a gpio
 # chip.
drivers/pinctrl/pinctrl.c +92 -0

123 lines not on this page · raw message

include/param.h +2 -0
index 59aa8a3a385f..1713a18c378e 100644
@@ -42,6 +42,8 @@ struct param_d {
 	enum param_type type;
 };
 
+#define PARAM_ENUM_UNKNOWN	(-1000000)
+
 enum param_tristate { PARAM_TRISTATE_UNKNOWN, PARAM_TRISTATE_TRUE, PARAM_TRISTATE_FALSE };
 
 #ifdef CONFIG_PARAMETER
include/pinctrl.h +10 -0
index 4ba7b489345b..5c031fb4008b 100644
@@ -25,4 +25,14 @@ struct pinctrl_device {
 int pinctrl_register(struct pinctrl_device *pdev);
 void pinctrl_unregister(struct pinctrl_device *pdev);
 
+#ifdef CONFIG_PINCTRL_STATE_PARAM
+void of_pinctrl_register_consumer(struct device *dev, struct device_node *np);
+void of_pinctrl_unregister_consumer(struct device *dev);
+#else
+static inline void of_pinctrl_register_consumer(struct device *dev, struct device_node *np)
+{
+}
+static inline void of_pinctrl_unregister_consumer(struct device *dev) {}
+#endif
+
 #endif /* PINCTRL_H */
lib/parameter.c +4 -2
index f36d77d119fa..b9a449c32657 100644
@@ -612,7 +612,9 @@ static const char *param_enum_get(struct bobject *bobj, struct param_d *p)
 
 	free(p->value);
 
-	if (*pe->value >= pe->num_names)
+	if (*pe->value == PARAM_ENUM_UNKNOWN)
+		p->value = strdup("unknown");
+	else if (*pe->value >= pe->num_names)
 		p->value = basprintf("invalid:%d", *pe->value);
 	else
 		p->value = strdup(pe->names[*pe->value]);
@@ -625,7 +627,7 @@ static void param_enum_info(struct param_d *p)
 	struct param_enum *pe = to_param_enum(p);
 	int i;
 
-	if (pe->num_names <= 1)
+	if (pe->num_names <= 1 && *pe->value != PARAM_ENUM_UNKNOWN)
 		return;
 
 	printf(" (values: ");
Signature · 1 line
2.47.3