]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
pinctrl: mediatek: print bias info along with pinmux
authorDavid Lechner <dlechner@baylibre.com>
Mon, 30 Mar 2026 16:00:35 +0000 (11:00 -0500)
committerDavid Lechner <dlechner@baylibre.com>
Tue, 7 Apr 2026 15:47:04 +0000 (10:47 -0500)
Add functionality to be able to print pin bias settings along with the
pinmux setting.

This can be useful to debug why pins might not be working correctly.

Reviewed-by: Macpaul Lin <macpaul.lin@mediatek.com>
Link: https://patch.msgid.link/20260330-pinctrl-mtk-fix-mt8189-v2-3-05a737ec623d@baylibre.com
Signed-off-by: David Lechner <dlechner@baylibre.com>
drivers/pinctrl/mediatek/pinctrl-mtk-common.c
drivers/pinctrl/mediatek/pinctrl-mtk-common.h

index 1028b8a93f589ce589952bf72d1abe2df131bf84..cfffbaeef84cda67cae74c42f0b033b1f05454ba 100644 (file)
@@ -237,9 +237,39 @@ static int mtk_get_pin_io_type(struct udevice *dev, int pin,
        io_type->bias_set = priv->soc->io_type[io_n].bias_set;
        io_type->drive_set = priv->soc->io_type[io_n].drive_set;
        io_type->input_enable = priv->soc->io_type[io_n].input_enable;
+       io_type->get_pinconf = priv->soc->io_type[io_n].get_pinconf;
 
        return 0;
 }
+
+static int mtk_pinconf_get(struct udevice *dev, u32 pin, char *buf, size_t size)
+{
+       struct mtk_io_type_desc io_type;
+       int err, pos;
+
+       /* If we fail to get the type, then we just don't add any more info. */
+       if (mtk_get_pin_io_type(dev, pin, &io_type))
+               return 0;
+
+       pos = snprintf(buf, size, " (%s)", io_type.name);
+       if (pos >= size)
+               return pos;
+
+       if (io_type.get_pinconf) {
+               err = io_type.get_pinconf(dev, pin, buf + pos, size - pos);
+               if (err < 0)
+                       return err;
+
+               pos += err;
+       }
+
+       return pos;
+}
+#else
+static int mtk_pinconf_get(struct udevice *dev, u32 pin, char *buf, size_t size)
+{
+       return 0;
+}
 #endif
 
 static int mtk_get_groups_count(struct udevice *dev)
@@ -270,12 +300,20 @@ static int mtk_get_pins_count(struct udevice *dev)
 static int mtk_get_pin_muxing(struct udevice *dev, unsigned int selector,
                              char *buf, int size)
 {
-       int val, err;
+       int val, err, pos;
+
        err = mtk_hw_get_value(dev, selector, PINCTRL_PIN_REG_MODE, &val);
        if (err)
                return err;
 
-       snprintf(buf, size, "Aux Func.%d", val);
+       pos = snprintf(buf, size, "Aux Func.%d", val);
+       if (pos >= size)
+               return 0;
+
+       err = mtk_pinconf_get(dev, selector, buf + pos, size - pos);
+       if (err < 0)
+               return err;
+
        return 0;
 }
 
@@ -670,6 +708,55 @@ static int mtk_pinconf_group_set(struct udevice *dev,
 
        return 0;
 }
+
+int mtk_pinconf_get_pu_pd(struct udevice *dev, u32 pin, char *buf, size_t size)
+{
+       int err, pu, pd;
+
+       err = mtk_hw_get_value(dev, pin, PINCTRL_PIN_REG_PU, &pu);
+       if (err)
+               return err;
+
+       err = mtk_hw_get_value(dev, pin, PINCTRL_PIN_REG_PD, &pd);
+       if (err)
+               return err;
+
+       return snprintf(buf, size, " PU:%d PD:%d", pu, pd);
+}
+
+int mtk_pinconf_get_pupd_r1_r0(struct udevice *dev, u32 pin, char *buf, size_t size)
+{
+       int err, r0, r1, pupd;
+
+       err = mtk_hw_get_value(dev, pin, PINCTRL_PIN_REG_PUPD, &pupd);
+       if (err)
+               return err;
+
+       err = mtk_hw_get_value(dev, pin, PINCTRL_PIN_REG_R1, &r1);
+       if (err)
+               return err;
+
+       err = mtk_hw_get_value(dev, pin, PINCTRL_PIN_REG_R0, &r0);
+       if (err)
+               return err;
+
+       return snprintf(buf, size, " PUPD:%d R1:%d R0:%d", pupd, r1, r0);
+}
+
+int mtk_pinconf_get_pu_pd_rsel(struct udevice *dev, u32 pin, char *buf, size_t size)
+{
+       int pos, err, rsel;
+
+       pos = mtk_pinconf_get_pu_pd(dev, pin, buf, size);
+       if (pos < 0 || pos >= size)
+               return pos;
+
+       err = mtk_hw_get_value(dev, pin, PINCTRL_PIN_REG_RSEL, &rsel);
+       if (err)
+               return err;
+
+       return pos + snprintf(buf + pos, size - pos, " RSEL:%d", rsel);
+}
 #endif
 
 static int mtk_pinctrl_pinmux_property_set(struct udevice *dev, u32 pinmux_group)
index 1215fb7094b6c24c8dfae5a63947d9e8d4c15b8f..bd17964090a3c01c742d4724c7ef4b5dc966cf08 100644 (file)
@@ -204,6 +204,7 @@ struct mtk_io_type_desc {
                        bool pullup, u32 val);
        int (*drive_set)(struct udevice *dev, u32 pin, u32 arg);
        int (*input_enable)(struct udevice *dev, u32 pin, u32 arg);
+       int (*get_pinconf)(struct udevice *dev, u32 pin, char *buf, size_t size);
 #endif
 };
 
@@ -263,6 +264,9 @@ int mtk_pinconf_bias_set_v1(struct udevice *dev, u32 pin, bool disable,
 int mtk_pinconf_input_enable_v1(struct udevice *dev, u32 pin, u32 arg);
 int mtk_pinconf_drive_set_v0(struct udevice *dev, u32 pin, u32 arg);
 int mtk_pinconf_drive_set_v1(struct udevice *dev, u32 pin, u32 arg);
+int mtk_pinconf_get_pu_pd(struct udevice *dev, u32 pin, char *buf, size_t size);
+int mtk_pinconf_get_pupd_r1_r0(struct udevice *dev, u32 pin, char *buf, size_t size);
+int mtk_pinconf_get_pu_pd_rsel(struct udevice *dev, u32 pin, char *buf, size_t size);
 
 #endif