Re: [U-Boot] [PATCH 33/41] power: Add PD device lookup interface to power domain uclass

2018-05-30 Thread Simon Glass
Hi Peng,

On 28 May 2018 at 06:25, Peng Fan  wrote:
> 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 
> Signed-off-by: Peng Fan 
> Cc: Simon Glass 
> ---
>  drivers/power/domain/power-domain-uclass.c | 42 
> ++
>  include/power-domain.h | 15 +++
>  2 files changed, 57 insertions(+)
>

Please add a test to test/dm/power-domain.c for your newe function.

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 33/41] power: Add PD device lookup interface to power domain uclass

2018-05-28 Thread Peng Fan
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 
Signed-off-by: Peng Fan 
Cc: Simon Glass 
---
 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 
 #include 
 #include 
+#include 
+#include 
 
 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, );
+   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

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot