[PATCH 1/2] pinctrl: imx: answer OUTPUT_ENABLE/INPUT_ENABLE queries from the pad register

From: Mehmet Fide

Date: Wed Sep 02 2026 - 02:31:22 EST


From: Mehmet Fide <mehmet.fide@xxxxxxxxxxxxxxxxxx>

The mmio pinconf get callback ignores which parameter was requested and
returns the raw conf register, so a generic query through
pinctrl_gpio_get_config() gets register bits back instead of the packed
parameter it asked for.

Decode the requested parameter and answer PIN_CONFIG_OUTPUT_ENABLE and
PIN_CONFIG_INPUT_ENABLE on SoCs that declare where those bits live in
the pad register; Vybrid has OBE at bit 1 and IBE at bit 0. The answer
is 0 with the bit value as the argument, which is what the
pinctrl_gpio_get_config() users (gpio-by-pinctrl, and gpio-mmio in the
next patch) expect. Pins the device tree never configured have no
register offset and get -ENOTSUPP, without the error message meant for
configuration attempts. Other parameters keep the historic raw-register
behaviour, which the debugfs dump still relies on.

This gives gpio-mmio a way to read back the line direction on chips
whose direction lives in the pin controller.

Suggested-by: Bartosz Golaszewski <brgl@xxxxxxxxxx>
Signed-off-by: Mehmet Fide <mehmet.fide@xxxxxxxxxxxxxxxxxx>
---
drivers/pinctrl/freescale/pinctrl-imx.c | 30 +++++++++++++++++++++++
drivers/pinctrl/freescale/pinctrl-imx.h | 4 +++
drivers/pinctrl/freescale/pinctrl-vf610.c | 2 ++
3 files changed, 36 insertions(+)

diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index 9a45b376d36f..5da1a76b0141 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -21,6 +21,7 @@

#include <linux/pinctrl/machine.h>
#include <linux/pinctrl/pinconf.h>
+#include <linux/pinctrl/pinconf-generic.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/pinctrl/pinmux.h>

@@ -297,6 +298,35 @@ static int imx_pinconf_get_mmio(struct pinctrl_dev *pctldev, unsigned pin_id,
struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
const struct imx_pinctrl_soc_info *info = ipctl->info;
const struct imx_pin_reg *pin_reg = &ipctl->pin_regs[pin_id];
+ enum pin_config_param param = pinconf_to_config_param(*config);
+ unsigned int mask = 0;
+ u32 raw;
+
+ /*
+ * Only OUTPUT_ENABLE/INPUT_ENABLE are decoded, and only when the SoC
+ * declares the bits. Everything else still returns the raw conf
+ * register, the debugfs dump depends on it.
+ */
+ switch (param) {
+ case PIN_CONFIG_OUTPUT_ENABLE:
+ mask = info->obe_mask;
+ break;
+ case PIN_CONFIG_INPUT_ENABLE:
+ mask = info->ibe_mask;
+ break;
+ default:
+ break;
+ }
+
+ if (mask) {
+ /* pin not configured, nothing to report */
+ if (pin_reg->conf_reg == -1)
+ return -ENOTSUPP;
+
+ raw = readl(ipctl->base + pin_reg->conf_reg);
+ *config = pinconf_to_config_packed(param, !!(raw & mask));
+ return 0;
+ }

if (pin_reg->conf_reg == -1) {
dev_err(ipctl->dev, "Pin(%s) does not support config function\n",
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.h b/drivers/pinctrl/freescale/pinctrl-imx.h
index f65ff45b4003..8fa7e1e2521d 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.h
+++ b/drivers/pinctrl/freescale/pinctrl-imx.h
@@ -91,6 +91,10 @@ struct imx_pinctrl_soc_info {
unsigned int mux_mask;
u8 mux_shift;

+ /* OBE/IBE bits in the conf register, 0 if the pad does not have them */
+ unsigned int obe_mask;
+ unsigned int ibe_mask;
+
int (*gpio_set_direction)(struct pinctrl_dev *pctldev,
struct pinctrl_gpio_range *range,
unsigned offset,
diff --git a/drivers/pinctrl/freescale/pinctrl-vf610.c b/drivers/pinctrl/freescale/pinctrl-vf610.c
index 76a4bc0181a0..77d077618782 100644
--- a/drivers/pinctrl/freescale/pinctrl-vf610.c
+++ b/drivers/pinctrl/freescale/pinctrl-vf610.c
@@ -319,6 +319,8 @@ static const struct imx_pinctrl_soc_info vf610_pinctrl_info = {
.gpio_set_direction = vf610_pmx_gpio_set_direction,
.mux_mask = 0x700000,
.mux_shift = 20,
+ .obe_mask = 0x2,
+ .ibe_mask = 0x1,
};

static const struct of_device_id vf610_pinctrl_of_match[] = {
--
2.54.0