[U-Boot] [PATCH 33/41] power: Add PD device lookup interface to power domain uclass
Peng Fan
peng.fan at nxp.com
Mon May 28 12:25:18 UTC 2018
Add power_domain_lookup_name interface to power domain uclass to find
a power domain device by its DTB node name, not using its associated
client device.
Through this interface, we can operate the power domain devices directly.
This is needed for non-DM drivers.
Signed-off-by: Ye Li <ye.li at nxp.com>
Signed-off-by: Peng Fan <peng.fan at nxp.com>
Cc: Simon Glass <sjg at chromium.org>
---
drivers/power/domain/power-domain-uclass.c | 42 ++++++++++++++++++++++++++++++
include/power-domain.h | 15 +++++++++++
2 files changed, 57 insertions(+)
diff --git a/drivers/power/domain/power-domain-uclass.c b/drivers/power/domain/power-domain-uclass.c
index 9e9ec4f419..4e9bcbdfae 100644
--- a/drivers/power/domain/power-domain-uclass.c
+++ b/drivers/power/domain/power-domain-uclass.c
@@ -7,6 +7,8 @@
#include <dm.h>
#include <power-domain.h>
#include <power-domain-uclass.h>
+#include <dm/uclass-internal.h>
+#include <dm/device-internal.h>
static inline struct power_domain_ops *power_domain_dev_ops(struct udevice *dev)
{
@@ -28,6 +30,46 @@ static int power_domain_of_xlate_default(struct power_domain *power_domain,
return 0;
}
+int power_domain_lookup_name(const char *name,
+ struct power_domain *power_domain)
+{
+ struct udevice *dev;
+ struct power_domain_ops *ops;
+ int ret;
+
+ debug("%s(power_domain=%p name=%s)\n", __func__, power_domain, name);
+
+ ret = uclass_find_device_by_name(UCLASS_POWER_DOMAIN, name, &dev);
+ if (!ret) {
+ /* Probe the dev */
+ device_probe(dev);
+ ops = power_domain_dev_ops(dev);
+
+ power_domain->dev = dev;
+ if (ops->of_xlate)
+ ret = ops->of_xlate(power_domain, NULL);
+ else
+ ret = power_domain_of_xlate_default(power_domain, NULL);
+ if (ret) {
+ debug("of_xlate() failed: %d\n", ret);
+ return ret;
+ }
+
+ ret = ops->request(power_domain);
+ if (ret) {
+ debug("ops->request() failed: %d\n", ret);
+ return ret;
+ }
+
+ debug("%s ok: %s\n", __func__, dev->name);
+
+ return 0;
+ }
+
+ printf("%s fail: %s, ret = %d\n", __func__, name, ret);
+ return -EINVAL;
+}
+
int power_domain_get(struct udevice *dev, struct power_domain *power_domain)
{
struct ofnode_phandle_args args;
diff --git a/include/power-domain.h b/include/power-domain.h
index aba8c0f65c..9060b174c0 100644
--- a/include/power-domain.h
+++ b/include/power-domain.h
@@ -74,6 +74,21 @@ struct power_domain {
unsigned long id;
};
+/**
+ * power_domain_lookup_name - Lookup the power domain device by name.
+ *
+ * This looks up and requests a provider power domain by using its
+ * device name. This skip the associated client device, but directly
+ * get the power domain device.
+ *
+ * @name: The power domain device's name.
+ * @power_domain A pointer to a power domain struct to initialize.
+ * @return 0 if OK, or a negative error code.
+ */
+
+int power_domain_lookup_name(const char *name,
+ struct power_domain *power_domain);
+
/**
* power_domain_get - Get/request the power domain for a device.
*
--
2.14.1
More information about the U-Boot
mailing list