0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __LINUX_DEVFREQ_H__
0011 #define __LINUX_DEVFREQ_H__
0012
0013 #include <linux/device.h>
0014 #include <linux/notifier.h>
0015 #include <linux/pm_opp.h>
0016 #include <linux/pm_qos.h>
0017
0018
0019 #define DEVFREQ_GOV_SIMPLE_ONDEMAND "simple_ondemand"
0020 #define DEVFREQ_GOV_PERFORMANCE "performance"
0021 #define DEVFREQ_GOV_POWERSAVE "powersave"
0022 #define DEVFREQ_GOV_USERSPACE "userspace"
0023 #define DEVFREQ_GOV_PASSIVE "passive"
0024
0025
0026 #define DEVFREQ_TRANSITION_NOTIFIER (0)
0027
0028
0029 #define DEVFREQ_PRECHANGE (0)
0030 #define DEVFREQ_POSTCHANGE (1)
0031
0032
0033 enum devfreq_timer {
0034 DEVFREQ_TIMER_DEFERRABLE = 0,
0035 DEVFREQ_TIMER_DELAYED,
0036 DEVFREQ_TIMER_NUM,
0037 };
0038
0039 struct devfreq;
0040 struct devfreq_governor;
0041 struct devfreq_cpu_data;
0042 struct thermal_cooling_device;
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 struct devfreq_dev_status {
0060
0061 unsigned long total_time;
0062 unsigned long busy_time;
0063 unsigned long current_frequency;
0064 void *private_data;
0065 };
0066
0067
0068
0069
0070
0071
0072
0073 #define DEVFREQ_FLAG_LEAST_UPPER_BOUND 0x1
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 struct devfreq_dev_profile {
0108 unsigned long initial_freq;
0109 unsigned int polling_ms;
0110 enum devfreq_timer timer;
0111 bool is_cooling_device;
0112
0113 int (*target)(struct device *dev, unsigned long *freq, u32 flags);
0114 int (*get_dev_status)(struct device *dev,
0115 struct devfreq_dev_status *stat);
0116 int (*get_cur_freq)(struct device *dev, unsigned long *freq);
0117 void (*exit)(struct device *dev);
0118
0119 unsigned long *freq_table;
0120 unsigned int max_state;
0121 };
0122
0123
0124
0125
0126
0127
0128
0129
0130 struct devfreq_stats {
0131 unsigned int total_trans;
0132 unsigned int *trans_table;
0133 u64 *time_in_state;
0134 u64 last_update;
0135 };
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179 struct devfreq {
0180 struct list_head node;
0181
0182 struct mutex lock;
0183 struct device dev;
0184 struct devfreq_dev_profile *profile;
0185 const struct devfreq_governor *governor;
0186 struct opp_table *opp_table;
0187 struct notifier_block nb;
0188 struct delayed_work work;
0189
0190 unsigned long *freq_table;
0191 unsigned int max_state;
0192
0193 unsigned long previous_freq;
0194 struct devfreq_dev_status last_status;
0195
0196 void *data;
0197
0198 struct dev_pm_qos_request user_min_freq_req;
0199 struct dev_pm_qos_request user_max_freq_req;
0200 unsigned long scaling_min_freq;
0201 unsigned long scaling_max_freq;
0202 bool stop_polling;
0203
0204 unsigned long suspend_freq;
0205 unsigned long resume_freq;
0206 atomic_t suspend_count;
0207
0208
0209 struct devfreq_stats stats;
0210
0211 struct srcu_notifier_head transition_notifier_list;
0212
0213
0214 struct thermal_cooling_device *cdev;
0215
0216 struct notifier_block nb_min;
0217 struct notifier_block nb_max;
0218 };
0219
0220 struct devfreq_freqs {
0221 unsigned long old;
0222 unsigned long new;
0223 };
0224
0225 #if defined(CONFIG_PM_DEVFREQ)
0226 struct devfreq *devfreq_add_device(struct device *dev,
0227 struct devfreq_dev_profile *profile,
0228 const char *governor_name,
0229 void *data);
0230 int devfreq_remove_device(struct devfreq *devfreq);
0231 struct devfreq *devm_devfreq_add_device(struct device *dev,
0232 struct devfreq_dev_profile *profile,
0233 const char *governor_name,
0234 void *data);
0235 void devm_devfreq_remove_device(struct device *dev, struct devfreq *devfreq);
0236
0237
0238 int devfreq_suspend_device(struct devfreq *devfreq);
0239 int devfreq_resume_device(struct devfreq *devfreq);
0240
0241 void devfreq_suspend(void);
0242 void devfreq_resume(void);
0243
0244
0245 int update_devfreq(struct devfreq *devfreq);
0246
0247
0248 struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
0249 unsigned long *freq, u32 flags);
0250 int devfreq_register_opp_notifier(struct device *dev,
0251 struct devfreq *devfreq);
0252 int devfreq_unregister_opp_notifier(struct device *dev,
0253 struct devfreq *devfreq);
0254 int devm_devfreq_register_opp_notifier(struct device *dev,
0255 struct devfreq *devfreq);
0256 void devm_devfreq_unregister_opp_notifier(struct device *dev,
0257 struct devfreq *devfreq);
0258 int devfreq_register_notifier(struct devfreq *devfreq,
0259 struct notifier_block *nb,
0260 unsigned int list);
0261 int devfreq_unregister_notifier(struct devfreq *devfreq,
0262 struct notifier_block *nb,
0263 unsigned int list);
0264 int devm_devfreq_register_notifier(struct device *dev,
0265 struct devfreq *devfreq,
0266 struct notifier_block *nb,
0267 unsigned int list);
0268 void devm_devfreq_unregister_notifier(struct device *dev,
0269 struct devfreq *devfreq,
0270 struct notifier_block *nb,
0271 unsigned int list);
0272 struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node);
0273 struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev,
0274 const char *phandle_name, int index);
0275
0276 #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290 struct devfreq_simple_ondemand_data {
0291 unsigned int upthreshold;
0292 unsigned int downdifferential;
0293 };
0294 #endif
0295
0296 #if IS_ENABLED(CONFIG_DEVFREQ_GOV_PASSIVE)
0297 enum devfreq_parent_dev_type {
0298 DEVFREQ_PARENT_DEV,
0299 CPUFREQ_PARENT_DEV,
0300 };
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324 struct devfreq_passive_data {
0325
0326 struct devfreq *parent;
0327
0328
0329 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
0330
0331
0332 enum devfreq_parent_dev_type parent_type;
0333
0334
0335 struct devfreq *this;
0336 struct notifier_block nb;
0337 struct list_head cpu_data_list;
0338 };
0339 #endif
0340
0341 #else
0342 static inline struct devfreq *devfreq_add_device(struct device *dev,
0343 struct devfreq_dev_profile *profile,
0344 const char *governor_name,
0345 void *data)
0346 {
0347 return ERR_PTR(-ENOSYS);
0348 }
0349
0350 static inline int devfreq_remove_device(struct devfreq *devfreq)
0351 {
0352 return 0;
0353 }
0354
0355 static inline struct devfreq *devm_devfreq_add_device(struct device *dev,
0356 struct devfreq_dev_profile *profile,
0357 const char *governor_name,
0358 void *data)
0359 {
0360 return ERR_PTR(-ENOSYS);
0361 }
0362
0363 static inline void devm_devfreq_remove_device(struct device *dev,
0364 struct devfreq *devfreq)
0365 {
0366 }
0367
0368 static inline int devfreq_suspend_device(struct devfreq *devfreq)
0369 {
0370 return 0;
0371 }
0372
0373 static inline int devfreq_resume_device(struct devfreq *devfreq)
0374 {
0375 return 0;
0376 }
0377
0378 static inline void devfreq_suspend(void) {}
0379 static inline void devfreq_resume(void) {}
0380
0381 static inline struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
0382 unsigned long *freq, u32 flags)
0383 {
0384 return ERR_PTR(-EINVAL);
0385 }
0386
0387 static inline int devfreq_register_opp_notifier(struct device *dev,
0388 struct devfreq *devfreq)
0389 {
0390 return -EINVAL;
0391 }
0392
0393 static inline int devfreq_unregister_opp_notifier(struct device *dev,
0394 struct devfreq *devfreq)
0395 {
0396 return -EINVAL;
0397 }
0398
0399 static inline int devm_devfreq_register_opp_notifier(struct device *dev,
0400 struct devfreq *devfreq)
0401 {
0402 return -EINVAL;
0403 }
0404
0405 static inline void devm_devfreq_unregister_opp_notifier(struct device *dev,
0406 struct devfreq *devfreq)
0407 {
0408 }
0409
0410 static inline int devfreq_register_notifier(struct devfreq *devfreq,
0411 struct notifier_block *nb,
0412 unsigned int list)
0413 {
0414 return 0;
0415 }
0416
0417 static inline int devfreq_unregister_notifier(struct devfreq *devfreq,
0418 struct notifier_block *nb,
0419 unsigned int list)
0420 {
0421 return 0;
0422 }
0423
0424 static inline int devm_devfreq_register_notifier(struct device *dev,
0425 struct devfreq *devfreq,
0426 struct notifier_block *nb,
0427 unsigned int list)
0428 {
0429 return 0;
0430 }
0431
0432 static inline void devm_devfreq_unregister_notifier(struct device *dev,
0433 struct devfreq *devfreq,
0434 struct notifier_block *nb,
0435 unsigned int list)
0436 {
0437 }
0438
0439 static inline struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node)
0440 {
0441 return ERR_PTR(-ENODEV);
0442 }
0443
0444 static inline struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev,
0445 const char *phandle_name, int index)
0446 {
0447 return ERR_PTR(-ENODEV);
0448 }
0449
0450 static inline int devfreq_update_stats(struct devfreq *df)
0451 {
0452 return -EINVAL;
0453 }
0454 #endif
0455
0456 #endif