dm: syscon: Allow finding devices by driver data

We have a way to find a regmap by its syscon driver data value. Add the same
for syscon itself.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c
index 686c320..a0666d0 100644
--- a/drivers/core/syscon-uclass.c
+++ b/drivers/core/syscon-uclass.c
@@ -32,7 +32,7 @@
 	return regmap_init_mem(dev, &priv->regmap);
 }
 
-struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data)
+int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp)
 {
 	struct udevice *dev;
 	struct uclass *uc;
@@ -40,22 +40,29 @@
 
 	ret = uclass_get(UCLASS_SYSCON, &uc);
 	if (ret)
-		return ERR_PTR(ret);
+		return ret;
 	uclass_foreach_dev(dev, uc) {
 		if (dev->driver_data == driver_data) {
-			struct syscon_uc_info *priv;
-			int ret;
-
-			ret = device_probe(dev);
-			if (ret)
-				return ERR_PTR(ret);
-			priv = dev_get_uclass_priv(dev);
-
-			return priv->regmap;
+			*devp = dev;
+			return device_probe(dev);
 		}
 	}
 
+	return -ENODEV;
+}
+
+struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data)
+{
+	struct syscon_uc_info *priv;
+	struct udevice *dev;
+	int ret;
+
+	ret = syscon_get_by_driver_data(driver_data, &dev);
+	if (ret)
+		return ERR_PTR(ret);
+	priv = dev_get_uclass_priv(dev);
+
-	return ERR_PTR(-ENODEV);
+	return priv->regmap;
 }
 
 void *syscon_get_first_range(ulong driver_data)