Commit 2539f319 authored by Xiangwei Li's avatar Xiangwei Li Committed by Ma Wupeng
Browse files

PM / devfreq: event: Add devfreq_event_get_edev_by_dev function

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IBC4SJ



--------------------------------

When there is no devicetree association between devfreq device and
devfreq-events device, devfreq_event_dev cannot be obtained through the
devfreq_event_get_edev_by_phandle function.

Therefore, a new interface is added to obtain struct devfreq_event_dev
through the specified device.

Signed-off-by: default avatarXiangwei Li <liwei728@huawei.com>
parent 3ff0de83
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -256,6 +256,38 @@ struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(struct device *dev,
}
EXPORT_SYMBOL_GPL(devfreq_event_get_edev_by_phandle);

/**
 * devfreq_event_get_edev_by_dev() - Get the devfreq-event dev from
 *					 specified device.
 * @dev		: the pointer to the given device
 *
 * Note that this function return the pointer of devfreq-event device.
 */
struct devfreq_event_dev *devfreq_event_get_edev_by_dev(struct device *dev)
{
	struct devfreq_event_dev *edev;

	if (!dev)
		return ERR_PTR(-EINVAL);

	mutex_lock(&devfreq_event_list_lock);
	list_for_each_entry(edev, &devfreq_event_list, node) {
		if (edev->dev.parent == dev)
			goto out;
	}

	edev = NULL;
out:
	mutex_unlock(&devfreq_event_list_lock);

	if (!edev) {
		return ERR_PTR(-ENODEV);
	}

	return edev;
}
EXPORT_SYMBOL_GPL(devfreq_event_get_edev_by_dev);

/**
 * devfreq_event_get_edev_count() - Get the count of devfreq-event dev
 * @dev		: the pointer to the given device
+8 −0
Original line number Diff line number Diff line
@@ -109,6 +109,8 @@ extern struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(
				struct device *dev,
				const char *phandle_name,
				int index);
extern struct devfreq_event_dev *devfreq_event_get_edev_by_dev(
				struct device *dev);
extern int devfreq_event_get_edev_count(struct device *dev,
				const char *phandle_name);
extern struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
@@ -162,6 +164,12 @@ static inline struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(
	return ERR_PTR(-EINVAL);
}

static inline struct devfreq_event_dev *devfreq_event_get_edev_by_dev(
					struct device *dev)
{
	return ERR_PTR(-EINVAL);
}

static inline int devfreq_event_get_edev_count(struct device *dev,
					const char *phandle_name)
{