]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
pinctrl: mediatek: fix failing to get syscon
authorDavid Lechner <dlechner@baylibre.com>
Wed, 14 Jan 2026 22:37:19 +0000 (16:37 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 21 Jan 2026 19:30:55 +0000 (13:30 -0600)
Replace uclass_get_device_by_ofnode() with syscon_regmap_lookup_by_phandle()
to get the "mediatek,pctl-regmap" syscon device.

Depending on probe order, uclass_get_device_by_ofnode() may fail, but
syscon_regmap_lookup_by_phandle() has logic in it to handle that case
correctly.

The previous implementation could read more than one syscon if the
"mediatek,pctl-regmap" property had more than one phandle, but the one
board with a devicetree that does that is not supported in U-Boot yet,
so we can save that for later (it may never be needed).

Fixes: 424ceba18bfb ("pinctrl: mediatek: support mediatek,pctl-regmap property")
Signed-off-by: David Lechner <dlechner@baylibre.com>
drivers/pinctrl/mediatek/Kconfig
drivers/pinctrl/mediatek/pinctrl-mtk-common.c

index 4a698568a7e548acc7691543d13acd64bf350d24..ed4b02be0ddfe4d0a2a6b4d6a0855758009e668a 100644 (file)
@@ -2,6 +2,8 @@ if ARCH_MEDIATEK
 
 config PINCTRL_MTK
        depends on PINCTRL_GENERIC
+       select REGMAP
+       select SYSCON
        bool
 
 config PINCTRL_MT7622
index ff7cefcc8de1726024f7ccf9fd493822ca49346d..b1fdcd18027bf546214c6e714d9b56a1e9d64e1b 100644 (file)
 #include <asm/io.h>
 #include <asm-generic/gpio.h>
 #include <linux/bitops.h>
+#include <linux/err.h>
+#include <log.h>
+#include <regmap.h>
+#include <syscon.h>
 
 #include "pinctrl-mtk-common.h"
 
@@ -822,32 +826,17 @@ int mtk_pinctrl_common_probe(struct udevice *dev,
         * for the interrupt controller, so we only use the 1st one currently.
         */
        num_regmaps = dev_count_phandle_with_args(dev, "mediatek,pctl-regmap", NULL, 0);
-       if (num_regmaps > ARRAY_SIZE(priv->base))
-               return -EINVAL;
 
        if (num_regmaps > 0) {
-               for (i = 0; i < num_regmaps; i++) {
-                       struct ofnode_phandle_args args;
-                       struct udevice *syscon_dev;
-                       int ret;
-
-                       ret = dev_read_phandle_with_args(dev, "mediatek,pctl-regmap",
-                                                        NULL, 0, i, &args);
-                       if (ret)
-                               return ret;
-
-                       ret = uclass_get_device_by_ofnode(UCLASS_SYSCON,
-                                                         args.node,
-                                                         &syscon_dev);
-                       if (ret)
-                               return ret;
-
-                       addr = dev_read_addr_index(syscon_dev, 0);
-                       if (addr == FDT_ADDR_T_NONE)
-                               return -EINVAL;
-
-                       priv->base[i] = (void __iomem *)addr;
-               }
+               struct regmap *regmap;
+
+               regmap = syscon_regmap_lookup_by_phandle(dev, "mediatek,pctl-regmap");
+               if (IS_ERR(regmap))
+                       return log_msg_ret("regmap: ", PTR_ERR(regmap));
+
+               priv->base[0] = regmap_get_range(regmap, 0);
+               if (!priv->base[0])
+                       return log_msg_ret("range: ", -EINVAL);
 
                return 0;
        }