diff mbox series

[V2,1/2] pinctrl: bcm2835: Implement bcm2835_pinconf_get

Message ID 20240302095430.4871-2-wahrenst@gmx.net
State New
Headers show
Series pinctrl: bcm2835: Implement pin_conf_get | expand

Commit Message

Stefan Wahren March 2, 2024, 9:54 a.m. UTC
Even the driver already has implemented pin_dbg_show, it could
be helpful to implement pin_conf_get for a more generic behavior.
Contrary to the BCM2711, the BCM2835 SOC doesn't allow to read
the bias config, so the implementation is limited to the basics.

Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 drivers/pinctrl/bcm/pinctrl-bcm2835.c | 35 ++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

--
2.34.1

Comments

Andy Shevchenko March 2, 2024, 5:40 p.m. UTC | #1
Sat, Mar 02, 2024 at 10:54:29AM +0100, Stefan Wahren kirjoitti:
> Even the driver already has implemented pin_dbg_show, it could
> be helpful to implement pin_conf_get for a more generic behavior.
> Contrary to the BCM2711, the BCM2835 SOC doesn't allow to read
> the bias config, so the implementation is limited to the basics.

> +	switch (param) {
> +	case PIN_CONFIG_INPUT_ENABLE:
> +		if (fsel != BCM2835_FSEL_GPIO_IN)
> +			return -EINVAL;
> +
> +		*config = pinconf_to_config_packed(param, 1);

> +		return 0;

Either use break here (and in similar situations)...

> +	case PIN_CONFIG_OUTPUT_ENABLE:
> +		if (fsel != BCM2835_FSEL_GPIO_OUT)
> +			return -EINVAL;
> +
> +		*config = pinconf_to_config_packed(param, 1);
> +		return 0;
> +
> +	case PIN_CONFIG_OUTPUT:
> +		if (fsel != BCM2835_FSEL_GPIO_OUT)
> +			return -EINVAL;
> +
> +		val = bcm2835_gpio_get_bit(pc, GPLEV0, pin);
> +		*config = pinconf_to_config_packed(param, val);
> +		return 0;
> +
> +	default:
> +		break;

...and return from here directly.

> +	}
> +
>  	return -ENOTSUPP;

I.o.w. it's better to have a single point of returning a success code.

>  }
diff mbox series

Patch

diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
index 1489191a213f..b37c86ec6915 100644
--- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
@@ -1003,7 +1003,40 @@  static const struct pinmux_ops bcm2835_pmx_ops = {
 static int bcm2835_pinconf_get(struct pinctrl_dev *pctldev,
 			unsigned pin, unsigned long *config)
 {
-	/* No way to read back config in HW */
+	enum pin_config_param param = pinconf_to_config_param(*config);
+	struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
+	enum bcm2835_fsel fsel = bcm2835_pinctrl_fsel_get(pc, pin);
+	u32 val;
+
+	/* No way to read back bias config in HW */
+
+	switch (param) {
+	case PIN_CONFIG_INPUT_ENABLE:
+		if (fsel != BCM2835_FSEL_GPIO_IN)
+			return -EINVAL;
+
+		*config = pinconf_to_config_packed(param, 1);
+		return 0;
+
+	case PIN_CONFIG_OUTPUT_ENABLE:
+		if (fsel != BCM2835_FSEL_GPIO_OUT)
+			return -EINVAL;
+
+		*config = pinconf_to_config_packed(param, 1);
+		return 0;
+
+	case PIN_CONFIG_OUTPUT:
+		if (fsel != BCM2835_FSEL_GPIO_OUT)
+			return -EINVAL;
+
+		val = bcm2835_gpio_get_bit(pc, GPLEV0, pin);
+		*config = pinconf_to_config_packed(param, val);
+		return 0;
+
+	default:
+		break;
+	}
+
 	return -ENOTSUPP;
 }