Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * devfreq-event: a framework to provide raw data and events of devfreq devices
0004  *
0005  * Copyright (C) 2014 Samsung Electronics
0006  * Author: Chanwoo Choi <cw00.choi@samsung.com>
0007  */
0008 
0009 #ifndef __LINUX_DEVFREQ_EVENT_H__
0010 #define __LINUX_DEVFREQ_EVENT_H__
0011 
0012 #include <linux/device.h>
0013 
0014 /**
0015  * struct devfreq_event_dev - the devfreq-event device
0016  *
0017  * @node    : Contain the devfreq-event device that have been registered.
0018  * @dev     : the device registered by devfreq-event class. dev.parent is
0019  *        the device using devfreq-event.
0020  * @lock    : a mutex to protect accessing devfreq-event.
0021  * @enable_count: the number of enable function have been called.
0022  * @desc    : the description for devfreq-event device.
0023  *
0024  * This structure contains devfreq-event device information.
0025  */
0026 struct devfreq_event_dev {
0027     struct list_head node;
0028 
0029     struct device dev;
0030     struct mutex lock;
0031     u32 enable_count;
0032 
0033     const struct devfreq_event_desc *desc;
0034 };
0035 
0036 /**
0037  * struct devfreq_event_data - the devfreq-event data
0038  *
0039  * @load_count  : load count of devfreq-event device for the given period.
0040  * @total_count : total count of devfreq-event device for the given period.
0041  *        each count may represent a clock cycle, a time unit
0042  *        (ns/us/...), or anything the device driver wants.
0043  *        Generally, utilization is load_count / total_count.
0044  *
0045  * This structure contains the data of devfreq-event device for polling period.
0046  */
0047 struct devfreq_event_data {
0048     unsigned long load_count;
0049     unsigned long total_count;
0050 };
0051 
0052 /**
0053  * struct devfreq_event_ops - the operations of devfreq-event device
0054  *
0055  * @enable  : Enable the devfreq-event device.
0056  * @disable : Disable the devfreq-event device.
0057  * @reset   : Reset all setting of the devfreq-event device.
0058  * @set_event   : Set the specific event type for the devfreq-event device.
0059  * @get_event   : Get the result of the devfreq-event devie with specific
0060  *        event type.
0061  *
0062  * This structure contains devfreq-event device operations which can be
0063  * implemented by devfreq-event device drivers.
0064  */
0065 struct devfreq_event_ops {
0066     /* Optional functions */
0067     int (*enable)(struct devfreq_event_dev *edev);
0068     int (*disable)(struct devfreq_event_dev *edev);
0069     int (*reset)(struct devfreq_event_dev *edev);
0070 
0071     /* Mandatory functions */
0072     int (*set_event)(struct devfreq_event_dev *edev);
0073     int (*get_event)(struct devfreq_event_dev *edev,
0074              struct devfreq_event_data *edata);
0075 };
0076 
0077 /**
0078  * struct devfreq_event_desc - the descriptor of devfreq-event device
0079  *
0080  * @name    : the name of devfreq-event device.
0081  * @event_type  : the type of the event determined and used by driver
0082  * @driver_data : the private data for devfreq-event driver.
0083  * @ops     : the operation to control devfreq-event device.
0084  *
0085  * Each devfreq-event device is described with a this structure.
0086  * This structure contains the various data for devfreq-event device.
0087  * The event_type describes what is going to be counted in the register.
0088  * It might choose to count e.g. read requests, write data in bytes, etc.
0089  * The full supported list of types is present in specyfic header in:
0090  * include/dt-bindings/pmu/.
0091  */
0092 struct devfreq_event_desc {
0093     const char *name;
0094     u32 event_type;
0095     void *driver_data;
0096 
0097     const struct devfreq_event_ops *ops;
0098 };
0099 
0100 #if defined(CONFIG_PM_DEVFREQ_EVENT)
0101 extern int devfreq_event_enable_edev(struct devfreq_event_dev *edev);
0102 extern int devfreq_event_disable_edev(struct devfreq_event_dev *edev);
0103 extern bool devfreq_event_is_enabled(struct devfreq_event_dev *edev);
0104 extern int devfreq_event_set_event(struct devfreq_event_dev *edev);
0105 extern int devfreq_event_get_event(struct devfreq_event_dev *edev,
0106                 struct devfreq_event_data *edata);
0107 extern int devfreq_event_reset_event(struct devfreq_event_dev *edev);
0108 extern struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(
0109                 struct device *dev,
0110                 const char *phandle_name,
0111                 int index);
0112 extern int devfreq_event_get_edev_count(struct device *dev,
0113                 const char *phandle_name);
0114 extern struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
0115                 struct devfreq_event_desc *desc);
0116 extern int devfreq_event_remove_edev(struct devfreq_event_dev *edev);
0117 extern struct devfreq_event_dev *devm_devfreq_event_add_edev(struct device *dev,
0118                 struct devfreq_event_desc *desc);
0119 extern void devm_devfreq_event_remove_edev(struct device *dev,
0120                 struct devfreq_event_dev *edev);
0121 static inline void *devfreq_event_get_drvdata(struct devfreq_event_dev *edev)
0122 {
0123     return edev->desc->driver_data;
0124 }
0125 #else
0126 static inline int devfreq_event_enable_edev(struct devfreq_event_dev *edev)
0127 {
0128     return -EINVAL;
0129 }
0130 
0131 static inline int devfreq_event_disable_edev(struct devfreq_event_dev *edev)
0132 {
0133     return -EINVAL;
0134 }
0135 
0136 static inline bool devfreq_event_is_enabled(struct devfreq_event_dev *edev)
0137 {
0138     return false;
0139 }
0140 
0141 static inline int devfreq_event_set_event(struct devfreq_event_dev *edev)
0142 {
0143     return -EINVAL;
0144 }
0145 
0146 static inline int devfreq_event_get_event(struct devfreq_event_dev *edev,
0147                     struct devfreq_event_data *edata)
0148 {
0149     return -EINVAL;
0150 }
0151 
0152 static inline int devfreq_event_reset_event(struct devfreq_event_dev *edev)
0153 {
0154     return -EINVAL;
0155 }
0156 
0157 static inline struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(
0158                     struct device *dev,
0159                     const char *phandle_name,
0160                     int index)
0161 {
0162     return ERR_PTR(-EINVAL);
0163 }
0164 
0165 static inline int devfreq_event_get_edev_count(struct device *dev,
0166                     const char *phandle_name)
0167 {
0168     return -EINVAL;
0169 }
0170 
0171 static inline struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
0172                     struct devfreq_event_desc *desc)
0173 {
0174     return ERR_PTR(-EINVAL);
0175 }
0176 
0177 static inline int devfreq_event_remove_edev(struct devfreq_event_dev *edev)
0178 {
0179     return -EINVAL;
0180 }
0181 
0182 static inline struct devfreq_event_dev *devm_devfreq_event_add_edev(
0183                     struct device *dev,
0184                     struct devfreq_event_desc *desc)
0185 {
0186     return ERR_PTR(-EINVAL);
0187 }
0188 
0189 static inline void devm_devfreq_event_remove_edev(struct device *dev,
0190                     struct devfreq_event_dev *edev)
0191 {
0192 }
0193 
0194 static inline void *devfreq_event_get_drvdata(struct devfreq_event_dev *edev)
0195 {
0196     return NULL;
0197 }
0198 #endif /* CONFIG_PM_DEVFREQ_EVENT */
0199 
0200 #endif /* __LINUX_DEVFREQ_EVENT_H__ */