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