pinctrl: mediatek: fix failing to get syscon

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: 424ceba18b ("pinctrl: mediatek: support mediatek,pctl-regmap property")
Signed-off-by: David Lechner <dlechner@baylibre.com>
This commit is contained in:
David Lechner
2026-01-14 16:37:19 -06:00
committed by Tom Rini
parent c196b0a688
commit 04413ed0c1
2 changed files with 13 additions and 22 deletions

View File

@@ -2,6 +2,8 @@ if ARCH_MEDIATEK
config PINCTRL_MTK
depends on PINCTRL_GENERIC
select REGMAP
select SYSCON
bool
config PINCTRL_MT7622

View File

@@ -11,6 +11,10 @@
#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;
struct regmap *regmap;
ret = dev_read_phandle_with_args(dev, "mediatek,pctl-regmap",
NULL, 0, i, &args);
if (ret)
return ret;
regmap = syscon_regmap_lookup_by_phandle(dev, "mediatek,pctl-regmap");
if (IS_ERR(regmap))
return log_msg_ret("regmap: ", PTR_ERR(regmap));
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;
}
priv->base[0] = regmap_get_range(regmap, 0);
if (!priv->base[0])
return log_msg_ret("range: ", -EINVAL);
return 0;
}