]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
power_domain: Add power_domain_get_by_name()
authorMarek Vasut <marex@denx.de>
Tue, 12 Apr 2022 22:42:52 +0000 (00:42 +0200)
committerStefano Babic <sbabic@denx.de>
Thu, 21 Apr 2022 10:44:23 +0000 (12:44 +0200)
Implement power_domain_get_by_name() convenience function which parses
DT property 'power-domain-names' and looks up power domain by matching
name.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: Simon Glass <sjg@chromium.org>
drivers/power/domain/power-domain-uclass.c
include/power-domain.h

index 0c5823ceddf54e4e1b813fa90c85d7b7755c43ef..74c33d4e2e05cb0976bb7d0810eb67541461fb31 100644 (file)
@@ -80,6 +80,20 @@ int power_domain_get_by_index(struct udevice *dev,
        return 0;
 }
 
+int power_domain_get_by_name(struct udevice *dev,
+                            struct power_domain *power_domain, const char *name)
+{
+       int index;
+
+       index = dev_read_stringlist_search(dev, "power-domain-names", name);
+       if (index < 0) {
+               debug("fdt_stringlist_search() failed: %d\n", index);
+               return index;
+       }
+
+       return power_domain_get_by_index(dev, power_domain, index);
+}
+
 int power_domain_get(struct udevice *dev, struct power_domain *power_domain)
 {
        return power_domain_get_by_index(dev, power_domain, 0);
index 113276b5119314486860b193a62a1bebf4037455..2ff6c77cd765fe3791b8939d96c1c6abfb9f69b6 100644 (file)
@@ -107,6 +107,27 @@ int power_domain_get_by_index(struct udevice *dev,
 }
 #endif
 
+/**
+ * power_domain_get_by_name - Get the named power domain for a device.
+ *
+ * @dev:               The client device.
+ * @power_domain:      A pointer to a power domain struct to initialize.
+ * @name:              Power domain name to be powered on.
+ *
+ * Return: 0 if OK, or a negative error code.
+ */
+#if CONFIG_IS_ENABLED(POWER_DOMAIN)
+int power_domain_get_by_name(struct udevice *dev,
+                            struct power_domain *power_domain, const char *name);
+#else
+static inline
+int power_domain_get_by_name(struct udevice *dev,
+                            struct power_domain *power_domain, const char *name)
+{
+       return -ENOSYS;
+}
+#endif
+
 /**
  * power_domain_free - Free a previously requested power domain.
  *