]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: syscon: Allow finding devices by driver data
authorSimon Glass <sjg@chromium.org>
Sun, 17 Jan 2016 23:11:08 +0000 (16:11 -0700)
committerBin Meng <bmeng.cn@gmail.com>
Sun, 24 Jan 2016 04:07:19 +0000 (12:07 +0800)
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>
drivers/core/syscon-uclass.c
include/syscon.h
test/dm/syscon.c

index 686c32056ec6e38cb26b2a355471331b26d97382..a0666d0bacd7e2d8cfcaca0f8ae13d85f7256873 100644 (file)
@@ -32,7 +32,7 @@ static int syscon_pre_probe(struct udevice *dev)
        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 @@ struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data)
 
        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 ERR_PTR(-ENODEV);
+       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 priv->regmap;
 }
 
 void *syscon_get_first_range(ulong driver_data)
index c62ccd61b329b66461395cccd4d315e58975a972..4593b6e3ebfdb96e7869cc9cc88045eaa42cb35d 100644 (file)
@@ -32,6 +32,20 @@ struct syscon_ops {
  */
 struct regmap *syscon_get_regmap(struct udevice *dev);
 
+/**
+ * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
+ *
+ * Each system controller can be accessed by its driver data, which is
+ * assumed to be unique through the scope of all system controllers that
+ * are in use. This function looks up the controller given this driver data.
+ *
+ * @driver_data:       Driver data value to look up
+ * @devp:              Returns the controller correponding to @driver_data
+ * @return 0 on success, -ENODEV if the ID was not found, or other -ve error
+ *        code
+ */
+int syscon_get_by_driver_data(ulong driver_data, struct udevice **devp);
+
 /**
  * syscon_get_regmap_by_driver_data() - Look up a controller by its ID
  *
index 36424816b894303faa52b22a0ec8129326af6765..c40f5fc09dd89b7bdc877fd50be9ad239dc0f7d7 100644 (file)
@@ -29,3 +29,20 @@ static int dm_test_syscon_base(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_syscon_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test system controller finding */
+static int dm_test_syscon_by_driver_data(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       ut_assertok(syscon_get_by_driver_data(SYSCON0, &dev));
+       ut_asserteq(SYSCON0, dev->driver_data);
+
+       ut_assertok(syscon_get_by_driver_data(SYSCON1, &dev));
+       ut_asserteq(SYSCON1, dev->driver_data);
+
+       ut_asserteq(-ENODEV, syscon_get_by_driver_data(2, &dev));
+
+       return 0;
+}
+DM_TEST(dm_test_syscon_by_driver_data, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);