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: Xiangwei Li liwei728@huawei.com --- drivers/devfreq/devfreq-event.c | 32 ++++++++++++++++++++++++++++++++ include/linux/devfreq-event.h | 8 ++++++++ 2 files changed, 40 insertions(+)
diff --git a/drivers/devfreq/devfreq-event.c b/drivers/devfreq/devfreq-event.c index 3ebac2496679..cd5b12ddc448 100644 --- a/drivers/devfreq/devfreq-event.c +++ b/drivers/devfreq/devfreq-event.c @@ -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 diff --git a/include/linux/devfreq-event.h b/include/linux/devfreq-event.h index 4a50a5c71a5f..1c7f64f09126 100644 --- a/include/linux/devfreq-event.h +++ b/include/linux/devfreq-event.h @@ -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) {