]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
clk: Add clk_get_by_name_optional
authorSean Anderson <seanga2@gmail.com>
Sat, 15 Jan 2022 20:52:47 +0000 (15:52 -0500)
committerSean Anderson <seanga2@gmail.com>
Fri, 25 Feb 2022 06:41:04 +0000 (01:41 -0500)
This adds a helper function for clk_get_by_name in cases where the clock is
optional. Hopefully this helps point driver writers in the right direction.
Also convert some existing users.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20220115205247.566210-2-seanga2@gmail.com
drivers/clk/clk_zynq.c
drivers/rng/meson-rng.c
include/clk.h

index 18915c3e0429df025fe9b26ff61775f61326e715..e80500e382b86b2cfe3da136efab4953b86e8423 100644 (file)
@@ -472,8 +472,9 @@ static int zynq_clk_probe(struct udevice *dev)
 
        for (i = 0; i < 2; i++) {
                sprintf(name, "gem%d_emio_clk", i);
-               ret = clk_get_by_name(dev, name, &priv->gem_emio_clk[i]);
-               if (ret < 0 && ret != -ENODATA) {
+               ret = clk_get_by_name_optional(dev, name,
+                                              &priv->gem_emio_clk[i]);
+               if (ret) {
                        dev_err(dev, "failed to get %s clock\n", name);
                        return ret;
                }
index 5a4f45ad5afe79db0253eb97427eb9f80b8acf54..e0a1e8c7e046862bea34f7bc71d31b2a6790a1ba 100644 (file)
@@ -91,8 +91,8 @@ static int meson_rng_of_to_plat(struct udevice *dev)
                return -ENODEV;
 
        /* Get optional "core" clock */
-       err = clk_get_by_name(dev, "core", &pdata->clk);
-       if (err && err != -ENODATA)
+       err = clk_get_by_name_optional(dev, "core", &pdata->clk);
+       if (err)
                return err;
 
        return 0;
index 303b04a726e79fe9f5846f2c6ac00092289f8952..23e4d4ea729e7831b1af74f2905084c9abaeb2ca 100644 (file)
@@ -287,6 +287,30 @@ static inline int clk_release_all(struct clk *clk, int count)
 }
 #endif
 
+/**
+ * clk_get_by_name_optional() - Get/request a optional clock by name.
+ * @dev:       The client device.
+ * @name:      The name of the clock to request, within the client's list of
+ *             clocks.
+ * @clk:       A pointer to a clock struct to initialize.
+ *
+ * Behaves the same as clk_get_by_name(), except when there is no clock
+ * provider. In the latter case, return 0.
+ *
+ * Return: 0 if OK, or a negative error code.
+ */
+static inline int clk_get_by_name_optional(struct udevice *dev,
+                                          const char *name, struct clk *clk)
+{
+       int ret;
+
+       ret = clk_get_by_name(dev, name, clk);
+       if (ret == -ENODATA)
+               return 0;
+
+       return ret;
+}
+
 /**
  * clk_get_by_name_nodev_optional - Get/request an optinonal clock by name
  *             without a device.