diff mbox series

[V2,2/2] pinctrl: bcm2835: Implement bcm2711_pinconf_get

Message ID 20240302095430.4871-3-wahrenst@gmx.net (mailing list archive)
State New, archived
Headers show
Series pinctrl: bcm2835: Implement pin_conf_get | expand

Commit Message

Stefan Wahren March 2, 2024, 9:54 a.m. UTC
The BCM2711 allows to read the bias config. So implement pin_conf_get
accordingly. The pull resistor values has been taken from the
BCM2711/7211 datasheet.

This implementation assumes that BCM7211 behaves the same way.

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

--
2.34.1

Comments

Andy Shevchenko March 2, 2024, 5:42 p.m. UTC | #1
Sat, Mar 02, 2024 at 10:54:30AM +0100, Stefan Wahren kirjoitti:
> The BCM2711 allows to read the bias config. So implement pin_conf_get
> accordingly. The pull resistor values has been taken from the
> BCM2711/7211 datasheet.
> 
> This implementation assumes that BCM7211 behaves the same way.

...

> +	switch (param) {
> +	case PIN_CONFIG_BIAS_DISABLE:
> +		if (((val >> shift) & PUD_2711_MASK) == BCM2711_PULL_NONE)
> +			return 0;
> +		else
> +			return -EINVAL;

Redundant 'else' in all cases. Also as in previous patch, use single return point of success.

		if (((val >> shift) & PUD_2711_MASK) != BCM2711_PULL_NONE)
			return -EINVAL;
		break;

> +	case PIN_CONFIG_BIAS_PULL_UP:
> +		if (((val >> shift) & PUD_2711_MASK) == BCM2711_PULL_UP) {
> +			*config = pinconf_to_config_packed(param, 50000);
> +			return 0;
> +		} else {
> +			return -EINVAL;
> +		}
> +
> +	case PIN_CONFIG_BIAS_PULL_DOWN:
> +		if (((val >> shift) & PUD_2711_MASK) == BCM2711_PULL_DOWN) {
> +			*config = pinconf_to_config_packed(param, 50000);
> +			return 0;
> +		} else {
> +			return -EINVAL;
> +		}
> +
> +	default:
> +		break;

Return directly from here.

		return bcm2835_pinconf_get(pctldev, pin, config);

> +	}
> +
> +	return bcm2835_pinconf_get(pctldev, pin, config);

	return 0;

> +}
diff mbox series

Patch

diff --git a/drivers/pinctrl/bcm/pinctrl-bcm2835.c b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
index b37c86ec6915..fcb9ab6729c0 100644
--- a/drivers/pinctrl/bcm/pinctrl-bcm2835.c
+++ b/drivers/pinctrl/bcm/pinctrl-bcm2835.c
@@ -1112,6 +1112,47 @@  static const struct pinconf_ops bcm2835_pinconf_ops = {
 	.pin_config_set = bcm2835_pinconf_set,
 };

+static int bcm2711_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin,
+			       unsigned long *config)
+{
+	struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
+	enum pin_config_param param = pinconf_to_config_param(*config);
+	u32 offset, shift, val;
+
+	offset = PUD_2711_REG_OFFSET(pin);
+	shift = PUD_2711_REG_SHIFT(pin);
+	val = bcm2835_gpio_rd(pc, GP_GPIO_PUP_PDN_CNTRL_REG0 + (offset * 4));
+
+	switch (param) {
+	case PIN_CONFIG_BIAS_DISABLE:
+		if (((val >> shift) & PUD_2711_MASK) == BCM2711_PULL_NONE)
+			return 0;
+		else
+			return -EINVAL;
+
+	case PIN_CONFIG_BIAS_PULL_UP:
+		if (((val >> shift) & PUD_2711_MASK) == BCM2711_PULL_UP) {
+			*config = pinconf_to_config_packed(param, 50000);
+			return 0;
+		} else {
+			return -EINVAL;
+		}
+
+	case PIN_CONFIG_BIAS_PULL_DOWN:
+		if (((val >> shift) & PUD_2711_MASK) == BCM2711_PULL_DOWN) {
+			*config = pinconf_to_config_packed(param, 50000);
+			return 0;
+		} else {
+			return -EINVAL;
+		}
+
+	default:
+		break;
+	}
+
+	return bcm2835_pinconf_get(pctldev, pin, config);
+}
+
 static void bcm2711_pull_config_set(struct bcm2835_pinctrl *pc,
 				    unsigned int pin, unsigned int arg)
 {
@@ -1179,7 +1220,7 @@  static int bcm2711_pinconf_set(struct pinctrl_dev *pctldev,

 static const struct pinconf_ops bcm2711_pinconf_ops = {
 	.is_generic = true,
-	.pin_config_get = bcm2835_pinconf_get,
+	.pin_config_get = bcm2711_pinconf_get,
 	.pin_config_set = bcm2711_pinconf_set,
 };