MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * devfreq: Generic Dynamic Voltage and Frequency Scaling (DVFS) Framework |
| 3 | * for Non-CPU Devices. |
| 4 | * |
| 5 | * Copyright (C) 2011 Samsung Electronics |
| 6 | * MyungJoo Ham <myungjoo.ham@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __LINUX_DEVFREQ_H__ |
| 14 | #define __LINUX_DEVFREQ_H__ |
| 15 | |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/notifier.h> |
Nishanth Menon | e4db1c7 | 2013-09-19 16:03:52 -0500 | [diff] [blame] | 18 | #include <linux/pm_opp.h> |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 19 | |
| 20 | #define DEVFREQ_NAME_LEN 16 |
| 21 | |
Chanwoo Choi | 0fe3a66 | 2016-01-26 13:21:26 +0900 | [diff] [blame] | 22 | /* DEVFREQ notifier interface */ |
| 23 | #define DEVFREQ_TRANSITION_NOTIFIER (0) |
| 24 | |
| 25 | /* Transition notifiers of DEVFREQ_TRANSITION_NOTIFIER */ |
| 26 | #define DEVFREQ_PRECHANGE (0) |
| 27 | #define DEVFREQ_POSTCHANGE (1) |
| 28 | |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 29 | struct devfreq; |
| 30 | |
| 31 | /** |
| 32 | * struct devfreq_dev_status - Data given from devfreq user device to |
| 33 | * governors. Represents the performance |
| 34 | * statistics. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 35 | * @total_time: The total time represented by this instance of |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 36 | * devfreq_dev_status |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 37 | * @busy_time: The time that the device was working among the |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 38 | * total_time. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 39 | * @current_frequency: The operating frequency. |
| 40 | * @private_data: An entry not specified by the devfreq framework. |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 41 | * A device and a specific governor may have their |
| 42 | * own protocol with private_data. However, because |
| 43 | * this is governor-specific, a governor using this |
| 44 | * will be only compatible with devices aware of it. |
| 45 | */ |
| 46 | struct devfreq_dev_status { |
| 47 | /* both since the last measure */ |
| 48 | unsigned long total_time; |
| 49 | unsigned long busy_time; |
| 50 | unsigned long current_frequency; |
Jonathan Corbet | 1a51cfd | 2011-11-07 23:54:53 +0100 | [diff] [blame] | 51 | void *private_data; |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
MyungJoo Ham | ab5f299 | 2012-03-16 21:54:53 +0100 | [diff] [blame] | 54 | /* |
| 55 | * The resulting frequency should be at most this. (this bound is the |
| 56 | * least upper bound; thus, the resulting freq should be lower or same) |
| 57 | * If the flag is not set, the resulting frequency should be at most the |
| 58 | * bound (greatest lower bound) |
| 59 | */ |
| 60 | #define DEVFREQ_FLAG_LEAST_UPPER_BOUND 0x1 |
| 61 | |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 62 | /** |
| 63 | * struct devfreq_dev_profile - Devfreq's user device profile |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 64 | * @initial_freq: The operating frequency when devfreq_add_device() is |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 65 | * called. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 66 | * @polling_ms: The polling interval in ms. 0 disables polling. |
| 67 | * @target: The device should set its operating frequency at |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 68 | * freq or lowest-upper-than-freq value. If freq is |
| 69 | * higher than any operable frequency, set maximum. |
| 70 | * Before returning, target function should set |
| 71 | * freq at the current frequency. |
MyungJoo Ham | ab5f299 | 2012-03-16 21:54:53 +0100 | [diff] [blame] | 72 | * The "flags" parameter's possible values are |
| 73 | * explained above with "DEVFREQ_FLAG_*" macros. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 74 | * @get_dev_status: The device should provide the current performance |
MyungJoo Ham | d54cdf3 | 2015-08-18 13:45:49 +0900 | [diff] [blame] | 75 | * status to devfreq. Governors are recommended not to |
| 76 | * use this directly. Instead, governors are recommended |
| 77 | * to use devfreq_update_stats() along with |
| 78 | * devfreq.last_status. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 79 | * @get_cur_freq: The device should provide the current frequency |
Rajagopal Venkat | 7f98a90 | 2012-10-26 01:50:26 +0200 | [diff] [blame] | 80 | * at which it is operating. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 81 | * @exit: An optional callback that is called when devfreq |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 82 | * is removing the devfreq object due to error or |
| 83 | * from devfreq_remove_device() call. If the user |
| 84 | * has registered devfreq->nb at a notifier-head, |
| 85 | * this is the time to unregister it. |
Jonghwa Lee | e552bba | 2012-08-23 20:00:46 +0900 | [diff] [blame] | 86 | * @freq_table: Optional list of frequencies to support statistics. |
| 87 | * @max_state: The size of freq_table. |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 88 | */ |
| 89 | struct devfreq_dev_profile { |
| 90 | unsigned long initial_freq; |
| 91 | unsigned int polling_ms; |
| 92 | |
MyungJoo Ham | ab5f299 | 2012-03-16 21:54:53 +0100 | [diff] [blame] | 93 | int (*target)(struct device *dev, unsigned long *freq, u32 flags); |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 94 | int (*get_dev_status)(struct device *dev, |
| 95 | struct devfreq_dev_status *stat); |
Rajagopal Venkat | 7f98a90 | 2012-10-26 01:50:26 +0200 | [diff] [blame] | 96 | int (*get_cur_freq)(struct device *dev, unsigned long *freq); |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 97 | void (*exit)(struct device *dev); |
Jonghwa Lee | e552bba | 2012-08-23 20:00:46 +0900 | [diff] [blame] | 98 | |
Chanwoo Choi | 0ec09ac | 2015-11-18 14:49:02 +0900 | [diff] [blame] | 99 | unsigned long *freq_table; |
Jonghwa Lee | e552bba | 2012-08-23 20:00:46 +0900 | [diff] [blame] | 100 | unsigned int max_state; |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | /** |
| 104 | * struct devfreq_governor - Devfreq policy governor |
Nishanth Menon | 3aa173b | 2012-10-29 15:01:43 -0500 | [diff] [blame] | 105 | * @node: list node - contains registered devfreq governors |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 106 | * @name: Governor's name |
Chanwoo Choi | 2294b77 | 2017-01-31 15:38:16 +0900 | [diff] [blame] | 107 | * @immutable: Immutable flag for governor. If the value is 1, |
| 108 | * this govenror is never changeable to other governor. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 109 | * @get_target_freq: Returns desired operating frequency for the device. |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 110 | * Basically, get_target_freq will run |
| 111 | * devfreq_dev_profile.get_dev_status() to get the |
| 112 | * status of the device (load = busy_time / total_time). |
| 113 | * If no_central_polling is set, this callback is called |
| 114 | * only with update_devfreq() notified by OPP. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 115 | * @event_handler: Callback for devfreq core framework to notify events |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 116 | * to governors. Events include per device governor |
| 117 | * init and exit, opp changes out of devfreq, suspend |
| 118 | * and resume of per device devfreq during device idle. |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 119 | * |
| 120 | * Note that the callbacks are called with devfreq->lock locked by devfreq. |
| 121 | */ |
| 122 | struct devfreq_governor { |
Nishanth Menon | 3aa173b | 2012-10-29 15:01:43 -0500 | [diff] [blame] | 123 | struct list_head node; |
| 124 | |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 125 | const char name[DEVFREQ_NAME_LEN]; |
Chanwoo Choi | 2294b77 | 2017-01-31 15:38:16 +0900 | [diff] [blame] | 126 | const unsigned int immutable; |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 127 | int (*get_target_freq)(struct devfreq *this, unsigned long *freq); |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 128 | int (*event_handler)(struct devfreq *devfreq, |
| 129 | unsigned int event, void *data); |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /** |
| 133 | * struct devfreq - Device devfreq structure |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 134 | * @node: list node - contains the devices with devfreq that have been |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 135 | * registered. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 136 | * @lock: a mutex to protect accessing devfreq. |
| 137 | * @dev: device registered by devfreq class. dev.parent is the device |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 138 | * using devfreq. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 139 | * @profile: device-specific devfreq profile |
| 140 | * @governor: method how to choose frequency based on the usage. |
Nishanth Menon | 1b5c1be | 2012-10-29 15:01:45 -0500 | [diff] [blame] | 141 | * @governor_name: devfreq governor name for use with this devfreq |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 142 | * @nb: notifier block used to notify devfreq object that it should |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 143 | * reevaluate operable frequencies. Devfreq users may use |
| 144 | * devfreq.nb to the corresponding register notifier call chain. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 145 | * @work: delayed work for load monitoring. |
| 146 | * @previous_freq: previously configured frequency value. |
| 147 | * @data: Private data of the governor. The devfreq framework does not |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 148 | * touch this. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 149 | * @min_freq: Limit minimum frequency requested by user (0: none) |
| 150 | * @max_freq: Limit maximum frequency requested by user (0: none) |
| 151 | * @stop_polling: devfreq polling status of a device. |
Jonghwa Lee | e552bba | 2012-08-23 20:00:46 +0900 | [diff] [blame] | 152 | * @total_trans: Number of devfreq transitions |
| 153 | * @trans_table: Statistics of devfreq transitions |
| 154 | * @time_in_state: Statistics of devfreq states |
| 155 | * @last_stat_updated: The last time stat updated |
Chanwoo Choi | 0fe3a66 | 2016-01-26 13:21:26 +0900 | [diff] [blame] | 156 | * @transition_notifier_list: list head of DEVFREQ_TRANSITION_NOTIFIER notifier |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 157 | * |
| 158 | * This structure stores the devfreq information for a give device. |
| 159 | * |
| 160 | * Note that when a governor accesses entries in struct devfreq in its |
| 161 | * functions except for the context of callbacks defined in struct |
| 162 | * devfreq_governor, the governor should protect its access with the |
| 163 | * struct mutex lock in struct devfreq. A governor may use this mutex |
| 164 | * to protect its own private data in void *data as well. |
| 165 | */ |
| 166 | struct devfreq { |
| 167 | struct list_head node; |
| 168 | |
| 169 | struct mutex lock; |
Jonathan Avila | 5a2f4ce | 2017-12-01 16:45:18 -0800 | [diff] [blame] | 170 | struct mutex sysfs_lock; |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 171 | struct device dev; |
| 172 | struct devfreq_dev_profile *profile; |
| 173 | const struct devfreq_governor *governor; |
Nishanth Menon | 1b5c1be | 2012-10-29 15:01:45 -0500 | [diff] [blame] | 174 | char governor_name[DEVFREQ_NAME_LEN]; |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 175 | struct notifier_block nb; |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 176 | struct delayed_work work; |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 177 | |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 178 | unsigned long previous_freq; |
Javi Merino | 08e75e7 | 2015-08-14 18:56:56 +0100 | [diff] [blame] | 179 | struct devfreq_dev_status last_status; |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 180 | |
| 181 | void *data; /* private data for governors */ |
| 182 | |
MyungJoo Ham | 6530b9de | 2011-12-09 16:42:19 +0900 | [diff] [blame] | 183 | unsigned long min_freq; |
| 184 | unsigned long max_freq; |
Rajagopal Venkat | 7e6fdd4 | 2012-10-26 01:50:09 +0200 | [diff] [blame] | 185 | bool stop_polling; |
Jonghwa Lee | e552bba | 2012-08-23 20:00:46 +0900 | [diff] [blame] | 186 | |
LABBE Corentin | 0585123 | 2013-09-26 16:50:21 +0200 | [diff] [blame] | 187 | /* information for device frequency transition */ |
Jonghwa Lee | e552bba | 2012-08-23 20:00:46 +0900 | [diff] [blame] | 188 | unsigned int total_trans; |
| 189 | unsigned int *trans_table; |
| 190 | unsigned long *time_in_state; |
| 191 | unsigned long last_stat_updated; |
Chanwoo Choi | 0fe3a66 | 2016-01-26 13:21:26 +0900 | [diff] [blame] | 192 | |
| 193 | struct srcu_notifier_head transition_notifier_list; |
| 194 | }; |
| 195 | |
| 196 | struct devfreq_freqs { |
| 197 | unsigned long old; |
| 198 | unsigned long new; |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | #if defined(CONFIG_PM_DEVFREQ) |
| 202 | extern struct devfreq *devfreq_add_device(struct device *dev, |
| 203 | struct devfreq_dev_profile *profile, |
Nishanth Menon | 1b5c1be | 2012-10-29 15:01:45 -0500 | [diff] [blame] | 204 | const char *governor_name, |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 205 | void *data); |
| 206 | extern int devfreq_remove_device(struct devfreq *devfreq); |
Chanwoo Choi | 8cd8409 | 2014-05-09 16:43:08 +0900 | [diff] [blame] | 207 | extern struct devfreq *devm_devfreq_add_device(struct device *dev, |
| 208 | struct devfreq_dev_profile *profile, |
| 209 | const char *governor_name, |
| 210 | void *data); |
| 211 | extern void devm_devfreq_remove_device(struct device *dev, |
| 212 | struct devfreq *devfreq); |
MyungJoo Ham | de9c739 | 2013-02-05 18:40:17 +0900 | [diff] [blame] | 213 | |
Rafael J. Wysocki | 464ed18 | 2014-12-19 15:37:54 +0100 | [diff] [blame] | 214 | /* Supposed to be called by PM callbacks */ |
Rajagopal Venkat | 206c30c | 2012-10-26 01:50:18 +0200 | [diff] [blame] | 215 | extern int devfreq_suspend_device(struct devfreq *devfreq); |
| 216 | extern int devfreq_resume_device(struct devfreq *devfreq); |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 217 | |
| 218 | /* Helper functions for devfreq user device driver with OPP. */ |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 219 | extern struct dev_pm_opp *devfreq_recommended_opp(struct device *dev, |
MyungJoo Ham | ab5f299 | 2012-03-16 21:54:53 +0100 | [diff] [blame] | 220 | unsigned long *freq, u32 flags); |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 221 | extern int devfreq_register_opp_notifier(struct device *dev, |
| 222 | struct devfreq *devfreq); |
| 223 | extern int devfreq_unregister_opp_notifier(struct device *dev, |
| 224 | struct devfreq *devfreq); |
Chanwoo Choi | d5b040d | 2014-05-09 16:43:09 +0900 | [diff] [blame] | 225 | extern int devm_devfreq_register_opp_notifier(struct device *dev, |
| 226 | struct devfreq *devfreq); |
| 227 | extern void devm_devfreq_unregister_opp_notifier(struct device *dev, |
| 228 | struct devfreq *devfreq); |
Chanwoo Choi | 0fe3a66 | 2016-01-26 13:21:26 +0900 | [diff] [blame] | 229 | extern int devfreq_register_notifier(struct devfreq *devfreq, |
| 230 | struct notifier_block *nb, |
| 231 | unsigned int list); |
| 232 | extern int devfreq_unregister_notifier(struct devfreq *devfreq, |
| 233 | struct notifier_block *nb, |
| 234 | unsigned int list); |
| 235 | extern int devm_devfreq_register_notifier(struct device *dev, |
| 236 | struct devfreq *devfreq, |
| 237 | struct notifier_block *nb, |
| 238 | unsigned int list); |
| 239 | extern void devm_devfreq_unregister_notifier(struct device *dev, |
| 240 | struct devfreq *devfreq, |
| 241 | struct notifier_block *nb, |
| 242 | unsigned int list); |
Chanwoo Choi | 8f510ae | 2015-11-10 20:31:07 +0900 | [diff] [blame] | 243 | extern struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, |
| 244 | int index); |
| 245 | |
Javi Merino | 08e75e7 | 2015-08-14 18:56:56 +0100 | [diff] [blame] | 246 | /** |
| 247 | * devfreq_update_stats() - update the last_status pointer in struct devfreq |
| 248 | * @df: the devfreq instance whose status needs updating |
MyungJoo Ham | d54cdf3 | 2015-08-18 13:45:49 +0900 | [diff] [blame] | 249 | * |
| 250 | * Governors are recommended to use this function along with last_status, |
| 251 | * which allows other entities to reuse the last_status without affecting |
| 252 | * the values fetched later by governors. |
Javi Merino | 08e75e7 | 2015-08-14 18:56:56 +0100 | [diff] [blame] | 253 | */ |
| 254 | static inline int devfreq_update_stats(struct devfreq *df) |
| 255 | { |
| 256 | return df->profile->get_dev_status(df->dev.parent, &df->last_status); |
| 257 | } |
| 258 | |
MyungJoo Ham | 883d588 | 2012-11-21 17:17:11 +0900 | [diff] [blame] | 259 | #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND) |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 260 | /** |
| 261 | * struct devfreq_simple_ondemand_data - void *data fed to struct devfreq |
| 262 | * and devfreq_add_device |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 263 | * @upthreshold: If the load is over this value, the frequency jumps. |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 264 | * Specify 0 to use the default. Valid value = 0 to 100. |
Nishanth Menon | e09651f | 2012-10-29 08:02:23 -0500 | [diff] [blame] | 265 | * @downdifferential: If the load is under upthreshold - downdifferential, |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 266 | * the governor may consider slowing the frequency down. |
| 267 | * Specify 0 to use the default. Valid value = 0 to 100. |
| 268 | * downdifferential < upthreshold must hold. |
Sahitya Tummala | 4b18548 | 2013-10-21 11:27:13 +0530 | [diff] [blame] | 269 | * @simple_scaling: Setting this flag will scale the clocks up only if the |
| 270 | * load is above @upthreshold and will scale the clocks |
| 271 | * down only if the load is below @downdifferential. |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 272 | * |
| 273 | * If the fed devfreq_simple_ondemand_data pointer is NULL to the governor, |
| 274 | * the governor uses the default values. |
| 275 | */ |
| 276 | struct devfreq_simple_ondemand_data { |
| 277 | unsigned int upthreshold; |
| 278 | unsigned int downdifferential; |
Sahitya Tummala | 4b18548 | 2013-10-21 11:27:13 +0530 | [diff] [blame] | 279 | unsigned int simple_scaling; |
MyungJoo Ham | ce26c5b | 2011-10-02 00:19:34 +0200 | [diff] [blame] | 280 | }; |
| 281 | #endif |
| 282 | |
Chanwoo Choi | 9961331 | 2016-03-22 13:44:03 +0900 | [diff] [blame] | 283 | #if IS_ENABLED(CONFIG_DEVFREQ_GOV_PASSIVE) |
| 284 | /** |
| 285 | * struct devfreq_passive_data - void *data fed to struct devfreq |
| 286 | * and devfreq_add_device |
| 287 | * @parent: the devfreq instance of parent device. |
| 288 | * @get_target_freq: Optional callback, Returns desired operating frequency |
| 289 | * for the device using passive governor. That is called |
| 290 | * when passive governor should decide the next frequency |
| 291 | * by using the new frequency of parent devfreq device |
| 292 | * using governors except for passive governor. |
| 293 | * If the devfreq device has the specific method to decide |
| 294 | * the next frequency, should use this callback. |
| 295 | * @this: the devfreq instance of own device. |
| 296 | * @nb: the notifier block for DEVFREQ_TRANSITION_NOTIFIER list |
| 297 | * |
| 298 | * The devfreq_passive_data have to set the devfreq instance of parent |
| 299 | * device with governors except for the passive governor. But, don't need to |
| 300 | * initialize the 'this' and 'nb' field because the devfreq core will handle |
| 301 | * them. |
| 302 | */ |
| 303 | struct devfreq_passive_data { |
| 304 | /* Should set the devfreq instance of parent device */ |
| 305 | struct devfreq *parent; |
| 306 | |
| 307 | /* Optional callback to decide the next frequency of passvice device */ |
| 308 | int (*get_target_freq)(struct devfreq *this, unsigned long *freq); |
| 309 | |
| 310 | /* For passive governor's internal use. Don't need to set them */ |
| 311 | struct devfreq *this; |
| 312 | struct notifier_block nb; |
| 313 | }; |
| 314 | #endif |
| 315 | |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 316 | #else /* !CONFIG_PM_DEVFREQ */ |
Rajagopal Venkat | 5faaa03 | 2013-03-21 13:28:25 +0000 | [diff] [blame] | 317 | static inline struct devfreq *devfreq_add_device(struct device *dev, |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 318 | struct devfreq_dev_profile *profile, |
Nishanth Menon | 1b5c1be | 2012-10-29 15:01:45 -0500 | [diff] [blame] | 319 | const char *governor_name, |
MyungJoo Ham | a95e1f5 | 2012-01-11 17:44:28 +0900 | [diff] [blame] | 320 | void *data) |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 321 | { |
Chanwoo Choi | 8cd8409 | 2014-05-09 16:43:08 +0900 | [diff] [blame] | 322 | return ERR_PTR(-ENOSYS); |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Rajagopal Venkat | 5faaa03 | 2013-03-21 13:28:25 +0000 | [diff] [blame] | 325 | static inline int devfreq_remove_device(struct devfreq *devfreq) |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 326 | { |
| 327 | return 0; |
| 328 | } |
| 329 | |
Chanwoo Choi | 8cd8409 | 2014-05-09 16:43:08 +0900 | [diff] [blame] | 330 | static inline struct devfreq *devm_devfreq_add_device(struct device *dev, |
| 331 | struct devfreq_dev_profile *profile, |
| 332 | const char *governor_name, |
| 333 | void *data) |
| 334 | { |
| 335 | return ERR_PTR(-ENOSYS); |
| 336 | } |
| 337 | |
| 338 | static inline void devm_devfreq_remove_device(struct device *dev, |
| 339 | struct devfreq *devfreq) |
| 340 | { |
| 341 | } |
| 342 | |
Rajagopal Venkat | 5faaa03 | 2013-03-21 13:28:25 +0000 | [diff] [blame] | 343 | static inline int devfreq_suspend_device(struct devfreq *devfreq) |
Rajagopal Venkat | 206c30c | 2012-10-26 01:50:18 +0200 | [diff] [blame] | 344 | { |
| 345 | return 0; |
| 346 | } |
| 347 | |
Rajagopal Venkat | 5faaa03 | 2013-03-21 13:28:25 +0000 | [diff] [blame] | 348 | static inline int devfreq_resume_device(struct devfreq *devfreq) |
Rajagopal Venkat | 206c30c | 2012-10-26 01:50:18 +0200 | [diff] [blame] | 349 | { |
| 350 | return 0; |
| 351 | } |
| 352 | |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 353 | static inline struct dev_pm_opp *devfreq_recommended_opp(struct device *dev, |
MyungJoo Ham | ab5f299 | 2012-03-16 21:54:53 +0100 | [diff] [blame] | 354 | unsigned long *freq, u32 flags) |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 355 | { |
Rajagopal Venkat | 5faaa03 | 2013-03-21 13:28:25 +0000 | [diff] [blame] | 356 | return ERR_PTR(-EINVAL); |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Rajagopal Venkat | 5faaa03 | 2013-03-21 13:28:25 +0000 | [diff] [blame] | 359 | static inline int devfreq_register_opp_notifier(struct device *dev, |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 360 | struct devfreq *devfreq) |
| 361 | { |
| 362 | return -EINVAL; |
| 363 | } |
| 364 | |
Rajagopal Venkat | 5faaa03 | 2013-03-21 13:28:25 +0000 | [diff] [blame] | 365 | static inline int devfreq_unregister_opp_notifier(struct device *dev, |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 366 | struct devfreq *devfreq) |
| 367 | { |
| 368 | return -EINVAL; |
| 369 | } |
| 370 | |
Chanwoo Choi | d5b040d | 2014-05-09 16:43:09 +0900 | [diff] [blame] | 371 | static inline int devm_devfreq_register_opp_notifier(struct device *dev, |
| 372 | struct devfreq *devfreq) |
| 373 | { |
| 374 | return -EINVAL; |
| 375 | } |
| 376 | |
| 377 | static inline void devm_devfreq_unregister_opp_notifier(struct device *dev, |
| 378 | struct devfreq *devfreq) |
| 379 | { |
| 380 | } |
Javi Merino | 08e75e7 | 2015-08-14 18:56:56 +0100 | [diff] [blame] | 381 | |
Chanwoo Choi | 0fe3a66 | 2016-01-26 13:21:26 +0900 | [diff] [blame] | 382 | static inline int devfreq_register_notifier(struct devfreq *devfreq, |
| 383 | struct notifier_block *nb, |
| 384 | unsigned int list) |
| 385 | { |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | static inline int devfreq_unregister_notifier(struct devfreq *devfreq, |
| 390 | struct notifier_block *nb, |
| 391 | unsigned int list) |
| 392 | { |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static inline int devm_devfreq_register_notifier(struct device *dev, |
| 397 | struct devfreq *devfreq, |
| 398 | struct notifier_block *nb, |
| 399 | unsigned int list) |
| 400 | { |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static inline void devm_devfreq_unregister_notifier(struct device *dev, |
| 405 | struct devfreq *devfreq, |
| 406 | struct notifier_block *nb, |
| 407 | unsigned int list) |
| 408 | { |
| 409 | } |
| 410 | |
Chanwoo Choi | 8f510ae | 2015-11-10 20:31:07 +0900 | [diff] [blame] | 411 | static inline struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, |
| 412 | int index) |
| 413 | { |
| 414 | return ERR_PTR(-ENODEV); |
| 415 | } |
| 416 | |
Javi Merino | 08e75e7 | 2015-08-14 18:56:56 +0100 | [diff] [blame] | 417 | static inline int devfreq_update_stats(struct devfreq *df) |
| 418 | { |
| 419 | return -EINVAL; |
| 420 | } |
MyungJoo Ham | a3c98b8 | 2011-10-02 00:19:15 +0200 | [diff] [blame] | 421 | #endif /* CONFIG_PM_DEVFREQ */ |
| 422 | |
| 423 | #endif /* __LINUX_DEVFREQ_H__ */ |