MLK-16118-2 power: Add PD device lookup interface to power domain uclass

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.

Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Ye Li <ye.li@nxp.com>
(cherry picked from commit f5fcb1903d935c2e1037b6a1fc61f1c290818727)
This commit is contained in:
Ye Li 2017-08-01 21:47:53 -05:00
parent 5fa9718410
commit 68b9f562f4
2 changed files with 56 additions and 1 deletions

View File

@ -3,11 +3,12 @@
*
* SPDX-License-Identifier: GPL-2.0
*/
#include <common.h>
#include <dm.h>
#include <power-domain.h>
#include <power-domain-uclass.h>
#include <dm/uclass-internal.h>
#include <dm/device-internal.h>
DECLARE_GLOBAL_DATA_PTR;
@ -31,6 +32,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;

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2016, NVIDIA CORPORATION.
* Copyright 2017 NXP
*
* SPDX-License-Identifier: GPL-2.0
*/
@ -75,6 +76,19 @@ struct power_domain {
unsigned long id;
};
/**
* power_domain_lookup_name - Lookup the power domain device by name and request it.
*
* 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.
*