[PATCH 8/9] pinctrl: rockchip: Add pinmux status related ops

Jonas Karlman jonas at kwiboo.se
Sun May 12 14:16:21 CEST 2024


Add get_pins_count(), get_pin_name() and get_pin_muxing() ops to support
the pinmux status cmd.

  => pinmux dev pinctrl
  dev: pinctrl
  => pinmux status
  GPIO0_A0  : gpio
  GPIO0_A1  : func-1
  GPIO0_A2  : gpio
  GPIO0_A3  : gpio
  GPIO0_A4  : func-1
  GPIO0_A5  : gpio
  GPIO0_A6  : gpio
  GPIO0_A7  : func-1
  GPIO0_B0  : gpio
  GPIO0_B1  : func-1
  GPIO0_B2  : func-1
  GPIO0_B3  : gpio
  [...]

The change to use ENOENT for unrouted pins also help hide a "Error -22"
message for unrouted pins using the gpio status -a cmd.

Signed-off-by: Jonas Karlman <jonas at kwiboo.se>
---
 .../pinctrl/rockchip/pinctrl-rockchip-core.c  | 50 ++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/rockchip/pinctrl-rockchip-core.c b/drivers/pinctrl/rockchip/pinctrl-rockchip-core.c
index 1a8eec19d268..fa24de37b443 100644
--- a/drivers/pinctrl/rockchip/pinctrl-rockchip-core.c
+++ b/drivers/pinctrl/rockchip/pinctrl-rockchip-core.c
@@ -127,7 +127,7 @@ static int rockchip_get_mux(struct rockchip_pin_bank *bank, int pin)
 
 	if (bank->iomux[iomux_num].type & IOMUX_UNROUTED) {
 		debug("pin %d is unrouted\n", pin);
-		return -EINVAL;
+		return -ENOENT;
 	}
 
 	if (bank->iomux[iomux_num].type & IOMUX_GPIO_ONLY)
@@ -194,6 +194,32 @@ static struct rockchip_pin_bank *rockchip_pin_to_bank(struct udevice *dev,
 	return NULL;
 }
 
+static int rockchip_pinctrl_get_pins_count(struct udevice *dev)
+{
+	struct rockchip_pinctrl_priv *priv = dev_get_priv(dev);
+	struct rockchip_pin_ctrl *ctrl = priv->ctrl;
+
+	return ctrl->nr_pins;
+}
+
+static const char *rockchip_pinctrl_get_pin_name(struct udevice *dev,
+						 unsigned int selector)
+{
+	static char name[PINNAME_SIZE];
+	struct rockchip_pin_bank *bank;
+	unsigned int index;
+
+	bank = rockchip_pin_to_bank(dev, selector);
+	if (!bank)
+		return NULL;
+
+	index = selector - bank->pin_base;
+	snprintf(name, sizeof(name), "GPIO%u_%c%u",
+		 bank->bank_num, 'A' + (index / 8), index % 8);
+
+	return name;
+}
+
 static int rockchip_pin_to_mux(struct udevice *dev, unsigned int pin)
 {
 	struct rockchip_pin_bank *bank;
@@ -222,6 +248,25 @@ static int rockchip_pinctrl_get_gpio_mux(struct udevice *dev, int banknum,
 	return rockchip_get_mux(&ctrl->pin_banks[banknum], index);
 }
 
+static int rockchip_pinctrl_get_pin_muxing(struct udevice *dev,
+					   unsigned int selector,
+					   char *buf, int size)
+{
+	int mux;
+
+	mux = rockchip_pin_to_mux(dev, selector);
+	if (mux == -ENOENT)
+		strlcpy(buf, "unrouted", size);
+	else if (mux < 0)
+		return mux;
+	else if (mux)
+		snprintf(buf, size, "func-%d", mux);
+	else
+		strlcpy(buf, "gpio", size);
+
+	return 0;
+}
+
 static int rockchip_verify_mux(struct rockchip_pin_bank *bank,
 			       int pin, int mux)
 {
@@ -571,8 +616,11 @@ static int rockchip_pinctrl_set_state(struct udevice *dev,
 }
 
 const struct pinctrl_ops rockchip_pinctrl_ops = {
+	.get_pins_count			= rockchip_pinctrl_get_pins_count,
+	.get_pin_name			= rockchip_pinctrl_get_pin_name,
 	.set_state			= rockchip_pinctrl_set_state,
 	.get_gpio_mux			= rockchip_pinctrl_get_gpio_mux,
+	.get_pin_muxing			= rockchip_pinctrl_get_pin_muxing,
 	.gpio_request_enable		= rockchip_pinctrl_gpio_request_enable,
 };
 
-- 
2.43.2



More information about the U-Boot mailing list