Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * devfreq-event: a framework to provide raw data and events of devfreq devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2015 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Chanwoo Choi <cw00.choi@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This driver is based on drivers/devfreq/devfreq.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/devfreq-event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static struct class *devfreq_event_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /* The list of all devfreq event list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static LIST_HEAD(devfreq_event_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static DEFINE_MUTEX(devfreq_event_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define to_devfreq_event(DEV) container_of(DEV, struct devfreq_event_dev, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * devfreq_event_enable_edev() - Enable the devfreq-event dev and increase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *				 the enable_count of devfreq-event dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * @edev	: the devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * Note that this function increase the enable_count and enable the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * devfreq-event device. The devfreq-event device should be enabled before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * using it by devfreq device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) int devfreq_event_enable_edev(struct devfreq_event_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (!edev || !edev->desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	mutex_lock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (edev->desc->ops && edev->desc->ops->enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			&& edev->enable_count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		ret = edev->desc->ops->enable(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	edev->enable_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	mutex_unlock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) EXPORT_SYMBOL_GPL(devfreq_event_enable_edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * devfreq_event_disable_edev() - Disable the devfreq-event dev and decrease
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *				  the enable_count of the devfreq-event dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * @edev	: the devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * Note that this function decrease the enable_count and disable the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * devfreq-event device. After the devfreq-event device is disabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * devfreq device can't use the devfreq-event device for get/set/reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) int devfreq_event_disable_edev(struct devfreq_event_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (!edev || !edev->desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	mutex_lock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (edev->enable_count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		dev_warn(&edev->dev, "unbalanced enable_count\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (edev->desc->ops && edev->desc->ops->disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			&& edev->enable_count == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		ret = edev->desc->ops->disable(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	edev->enable_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	mutex_unlock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) EXPORT_SYMBOL_GPL(devfreq_event_disable_edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * devfreq_event_is_enabled() - Check whether devfreq-event dev is enabled or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *				not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * @edev	: the devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * Note that this function check whether devfreq-event dev is enabled or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * If return true, the devfreq-event dev is enabeld. If return false, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * devfreq-event dev is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) bool devfreq_event_is_enabled(struct devfreq_event_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	bool enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!edev || !edev->desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	mutex_lock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (edev->enable_count > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	mutex_unlock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	return enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) EXPORT_SYMBOL_GPL(devfreq_event_is_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * devfreq_event_set_event() - Set event to devfreq-event dev to start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * @edev	: the devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * Note that this function set the event to the devfreq-event device to start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * for getting the event data which could be various event type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int devfreq_event_set_event(struct devfreq_event_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (!edev || !edev->desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (!edev->desc->ops || !edev->desc->ops->set_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (!devfreq_event_is_enabled(edev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	mutex_lock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	ret = edev->desc->ops->set_event(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	mutex_unlock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) EXPORT_SYMBOL_GPL(devfreq_event_set_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * devfreq_event_get_event() - Get {load|total}_count from devfreq-event dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * @edev	: the devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * @edata	: the calculated data of devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * Note that this function get the calculated event data from devfreq-event dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * after stoping the progress of whole sequence of devfreq-event dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int devfreq_event_get_event(struct devfreq_event_dev *edev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			    struct devfreq_event_data *edata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (!edev || !edev->desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!edev->desc->ops || !edev->desc->ops->get_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (!devfreq_event_is_enabled(edev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	edata->total_count = edata->load_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	mutex_lock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	ret = edev->desc->ops->get_event(edev, edata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		edata->total_count = edata->load_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	mutex_unlock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) EXPORT_SYMBOL_GPL(devfreq_event_get_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * devfreq_event_reset_event() - Reset all opeations of devfreq-event dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * @edev	: the devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * Note that this function stop all operations of devfreq-event dev and reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * the current event data to make the devfreq-event device into initial state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int devfreq_event_reset_event(struct devfreq_event_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!edev || !edev->desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (!devfreq_event_is_enabled(edev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	mutex_lock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (edev->desc->ops && edev->desc->ops->reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		ret = edev->desc->ops->reset(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	mutex_unlock(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) EXPORT_SYMBOL_GPL(devfreq_event_reset_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * devfreq_event_get_edev_by_phandle() - Get the devfreq-event dev from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  *					 devicetree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * @dev		: the pointer to the given device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * @phandle_name: name of property holding a phandle value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * @index	: the index into list of devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * Note that this function return the pointer of devfreq-event device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 					const char *phandle_name, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct devfreq_event_dev *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (!dev->of_node || !phandle_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	node = of_parse_phandle(dev->of_node, phandle_name, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	mutex_lock(&devfreq_event_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	list_for_each_entry(edev, &devfreq_event_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (edev->dev.parent && edev->dev.parent->of_node == node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	list_for_each_entry(edev, &devfreq_event_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		if (of_node_name_eq(node, edev->desc->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	edev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	mutex_unlock(&devfreq_event_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (!edev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	return edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) EXPORT_SYMBOL_GPL(devfreq_event_get_edev_by_phandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * devfreq_event_get_edev_count() - Get the count of devfreq-event dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * @dev		: the pointer to the given device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * @phandle_name: name of property holding a phandle value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * Note that this function return the count of devfreq-event devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int devfreq_event_get_edev_count(struct device *dev, const char *phandle_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!dev->of_node || !phandle_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		dev_err(dev, "device does not have a device node entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	count = of_property_count_elems_of_size(dev->of_node, phandle_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 						sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (count < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			"failed to get the count of devfreq-event in %pOF node\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			dev->of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) EXPORT_SYMBOL_GPL(devfreq_event_get_edev_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void devfreq_event_release_edev(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct devfreq_event_dev *edev = to_devfreq_event(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	kfree(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * devfreq_event_add_edev() - Add new devfreq-event device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  * @dev		: the device owning the devfreq-event device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * @desc	: the devfreq-event device's descriptor which include essential
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  *		  data for devfreq-event device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * Note that this function add new devfreq-event device to devfreq-event class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * list and register the device of the devfreq-event device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 						struct devfreq_event_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct devfreq_event_dev *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	static atomic_t event_no = ATOMIC_INIT(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (!dev || !desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (!desc->name || !desc->ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (!desc->ops->set_event || !desc->ops->get_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	edev = kzalloc(sizeof(struct devfreq_event_dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	mutex_init(&edev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	edev->desc = desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	edev->enable_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	edev->dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	edev->dev.class = devfreq_event_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	edev->dev.release = devfreq_event_release_edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	dev_set_name(&edev->dev, "event%d", atomic_inc_return(&event_no));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	ret = device_register(&edev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		put_device(&edev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	dev_set_drvdata(&edev->dev, edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	INIT_LIST_HEAD(&edev->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	mutex_lock(&devfreq_event_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	list_add(&edev->node, &devfreq_event_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	mutex_unlock(&devfreq_event_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) EXPORT_SYMBOL_GPL(devfreq_event_add_edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * devfreq_event_remove_edev() - Remove the devfreq-event device registered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * @edev	: the devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * Note that this function removes the registered devfreq-event device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int devfreq_event_remove_edev(struct devfreq_event_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	WARN_ON(edev->enable_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	mutex_lock(&devfreq_event_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	list_del(&edev->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	mutex_unlock(&devfreq_event_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	device_unregister(&edev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) EXPORT_SYMBOL_GPL(devfreq_event_remove_edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static int devm_devfreq_event_match(struct device *dev, void *res, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	struct devfreq_event_dev **r = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (WARN_ON(!r || !*r))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	return *r == data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static void devm_devfreq_event_release(struct device *dev, void *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	devfreq_event_remove_edev(*(struct devfreq_event_dev **)res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  * devm_devfreq_event_add_edev() - Resource-managed devfreq_event_add_edev()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  * @dev		: the device owning the devfreq-event device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  * @desc	: the devfreq-event device's descriptor which include essential
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  *		  data for devfreq-event device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * Note that this function manages automatically the memory of devfreq-event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  * device using device resource management and simplify the free operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * for memory of devfreq-event device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct devfreq_event_dev *devm_devfreq_event_add_edev(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 						struct devfreq_event_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct devfreq_event_dev **ptr, *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	ptr = devres_alloc(devm_devfreq_event_release, sizeof(*ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 				GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	edev = devfreq_event_add_edev(dev, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	if (IS_ERR(edev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		devres_free(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	*ptr = edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	devres_add(dev, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	return edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) EXPORT_SYMBOL_GPL(devm_devfreq_event_add_edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  * devm_devfreq_event_remove_edev()- Resource-managed devfreq_event_remove_edev()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  * @dev		: the device owning the devfreq-event device being created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  * @edev	: the devfreq-event device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  * Note that this function manages automatically the memory of devfreq-event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  * device using device resource management.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) void devm_devfreq_event_remove_edev(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 				struct devfreq_event_dev *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	WARN_ON(devres_release(dev, devm_devfreq_event_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			       devm_devfreq_event_match, edev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) EXPORT_SYMBOL_GPL(devm_devfreq_event_remove_edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  * Device attributes for devfreq-event class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static ssize_t name_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	struct devfreq_event_dev *edev = to_devfreq_event(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (!edev || !edev->desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	return sprintf(buf, "%s\n", edev->desc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static DEVICE_ATTR_RO(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static ssize_t enable_count_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 				  struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	struct devfreq_event_dev *edev = to_devfreq_event(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (!edev || !edev->desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	return sprintf(buf, "%d\n", edev->enable_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static DEVICE_ATTR_RO(enable_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static struct attribute *devfreq_event_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	&dev_attr_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	&dev_attr_enable_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) ATTRIBUTE_GROUPS(devfreq_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) static int __init devfreq_event_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	devfreq_event_class = class_create(THIS_MODULE, "devfreq-event");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	if (IS_ERR(devfreq_event_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		pr_err("%s: couldn't create class\n", __FILE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		return PTR_ERR(devfreq_event_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	devfreq_event_class->dev_groups = devfreq_event_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) subsys_initcall(devfreq_event_init);