1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Generic OPP Interface 4 * 5 * Copyright (C) 2009-2010 Texas Instruments Incorporated. 6 * Nishanth Menon 7 * Romit Dasgupta 8 * Kevin Hilman 9 */ 10 11 #ifndef __LINUX_OPP_H__ 12 #define __LINUX_OPP_H__ 13 14 #include <linux/energy_model.h> 15 #include <linux/err.h> 16 #include <linux/notifier.h> 17 18 struct clk; 19 struct regulator; 20 struct dev_pm_opp; 21 struct device; 22 struct opp_table; 23 24 enum dev_pm_opp_event { 25 OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE, 26 OPP_EVENT_ADJUST_VOLTAGE, 27 }; 28 29 /** 30 * struct dev_pm_opp_supply - Power supply voltage/current values 31 * @u_volt: Target voltage in microvolts corresponding to this OPP 32 * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP 33 * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP 34 * @u_amp: Maximum current drawn by the device in microamperes 35 * 36 * This structure stores the voltage/current values for a single power supply. 37 */ 38 struct dev_pm_opp_supply { 39 unsigned long u_volt; 40 unsigned long u_volt_min; 41 unsigned long u_volt_max; 42 unsigned long u_amp; 43 }; 44 45 /** 46 * struct dev_pm_opp_icc_bw - Interconnect bandwidth values 47 * @avg: Average bandwidth corresponding to this OPP (in icc units) 48 * @peak: Peak bandwidth corresponding to this OPP (in icc units) 49 * 50 * This structure stores the bandwidth values for a single interconnect path. 51 */ 52 struct dev_pm_opp_icc_bw { 53 u32 avg; 54 u32 peak; 55 }; 56 57 /** 58 * struct dev_pm_opp_info - OPP freq/voltage/current values 59 * @rate: Target clk rate in hz 60 * @supplies: Array of voltage/current values for all power supplies 61 * 62 * This structure stores the freq/voltage/current values for a single OPP. 63 */ 64 struct dev_pm_opp_info { 65 unsigned long rate; 66 struct dev_pm_opp_supply *supplies; 67 }; 68 69 /** 70 * struct dev_pm_set_opp_data - Set OPP data 71 * @old_opp: Old OPP info 72 * @new_opp: New OPP info 73 * @regulators: Array of regulator pointers 74 * @regulator_count: Number of regulators 75 * @clk: Pointer to clk 76 * @dev: Pointer to the struct device 77 * 78 * This structure contains all information required for setting an OPP. 79 */ 80 struct dev_pm_set_opp_data { 81 struct dev_pm_opp_info old_opp; 82 struct dev_pm_opp_info new_opp; 83 84 struct regulator **regulators; 85 unsigned int regulator_count; 86 struct clk *clk; 87 struct device *dev; 88 }; 89 90 #if defined(CONFIG_PM_OPP) 91 92 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); 93 struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index); 94 void dev_pm_opp_put_opp_table(struct opp_table *opp_table); 95 96 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp); 97 98 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp); 99 100 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp); 101 102 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp); 103 104 int dev_pm_opp_get_opp_count(struct device *dev); 105 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev); 106 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev); 107 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev); 108 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev); 109 110 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, 111 unsigned long freq, 112 bool available); 113 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, 114 unsigned int level); 115 116 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, 117 unsigned long *freq); 118 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, 119 unsigned long u_volt); 120 121 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, 122 unsigned long *freq); 123 void dev_pm_opp_put(struct dev_pm_opp *opp); 124 125 int dev_pm_opp_add(struct device *dev, unsigned long freq, 126 unsigned long u_volt); 127 void dev_pm_opp_remove(struct device *dev, unsigned long freq); 128 void dev_pm_opp_remove_all_dynamic(struct device *dev); 129 130 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, 131 unsigned long u_volt, unsigned long u_volt_min, 132 unsigned long u_volt_max); 133 134 int dev_pm_opp_enable(struct device *dev, unsigned long freq); 135 136 int dev_pm_opp_disable(struct device *dev, unsigned long freq); 137 138 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb); 139 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb); 140 141 struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count); 142 void dev_pm_opp_put_supported_hw(struct opp_table *opp_table); 143 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name); 144 void dev_pm_opp_put_prop_name(struct opp_table *opp_table); 145 struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count); 146 void dev_pm_opp_put_regulators(struct opp_table *opp_table); 147 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name); 148 void dev_pm_opp_put_clkname(struct opp_table *opp_table); 149 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); 150 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); 151 struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs); 152 void dev_pm_opp_detach_genpd(struct opp_table *opp_table); 153 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate); 154 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); 155 int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp); 156 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); 157 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); 158 void dev_pm_opp_remove_table(struct device *dev); 159 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask); 160 #else 161 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) 162 { 163 return ERR_PTR(-ENOTSUPP); 164 } 165 166 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index) 167 { 168 return ERR_PTR(-ENOTSUPP); 169 } 170 171 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} 172 173 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) 174 { 175 return 0; 176 } 177 178 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp) 179 { 180 return 0; 181 } 182 183 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) 184 { 185 return 0; 186 } 187 188 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp) 189 { 190 return false; 191 } 192 193 static inline int dev_pm_opp_get_opp_count(struct device *dev) 194 { 195 return 0; 196 } 197 198 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev) 199 { 200 return 0; 201 } 202 203 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) 204 { 205 return 0; 206 } 207 208 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev) 209 { 210 return 0; 211 } 212 213 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) 214 { 215 return 0; 216 } 217 218 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, 219 unsigned long freq, bool available) 220 { 221 return ERR_PTR(-ENOTSUPP); 222 } 223 224 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, 225 unsigned int level) 226 { 227 return ERR_PTR(-ENOTSUPP); 228 } 229 230 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, 231 unsigned long *freq) 232 { 233 return ERR_PTR(-ENOTSUPP); 234 } 235 236 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, 237 unsigned long u_volt) 238 { 239 return ERR_PTR(-ENOTSUPP); 240 } 241 242 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, 243 unsigned long *freq) 244 { 245 return ERR_PTR(-ENOTSUPP); 246 } 247 248 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} 249 250 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq, 251 unsigned long u_volt) 252 { 253 return -ENOTSUPP; 254 } 255 256 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq) 257 { 258 } 259 260 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev) 261 { 262 } 263 264 static inline int 265 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, 266 unsigned long u_volt, unsigned long u_volt_min, 267 unsigned long u_volt_max) 268 { 269 return 0; 270 } 271 272 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq) 273 { 274 return 0; 275 } 276 277 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq) 278 { 279 return 0; 280 } 281 282 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb) 283 { 284 return -ENOTSUPP; 285 } 286 287 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb) 288 { 289 return -ENOTSUPP; 290 } 291 292 static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, 293 const u32 *versions, 294 unsigned int count) 295 { 296 return ERR_PTR(-ENOTSUPP); 297 } 298 299 static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {} 300 301 static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, 302 int (*set_opp)(struct dev_pm_set_opp_data *data)) 303 { 304 return ERR_PTR(-ENOTSUPP); 305 } 306 307 static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {} 308 309 static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) 310 { 311 return ERR_PTR(-ENOTSUPP); 312 } 313 314 static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} 315 316 static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count) 317 { 318 return ERR_PTR(-ENOTSUPP); 319 } 320 321 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {} 322 323 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name) 324 { 325 return ERR_PTR(-ENOTSUPP); 326 } 327 328 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {} 329 330 static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs) 331 { 332 return ERR_PTR(-ENOTSUPP); 333 } 334 335 static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {} 336 337 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate) 338 { 339 return -ENOTSUPP; 340 } 341 342 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) 343 { 344 return -ENOTSUPP; 345 } 346 347 static inline int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp) 348 { 349 return -EOPNOTSUPP; 350 } 351 352 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask) 353 { 354 return -ENOTSUPP; 355 } 356 357 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) 358 { 359 return -EINVAL; 360 } 361 362 static inline void dev_pm_opp_remove_table(struct device *dev) 363 { 364 } 365 366 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask) 367 { 368 } 369 370 #endif /* CONFIG_PM_OPP */ 371 372 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) 373 int dev_pm_opp_of_add_table(struct device *dev); 374 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index); 375 void dev_pm_opp_of_remove_table(struct device *dev); 376 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); 377 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask); 378 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); 379 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); 380 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp); 381 int of_get_required_opp_performance_state(struct device_node *np, int index); 382 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table); 383 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus); 384 static inline void dev_pm_opp_of_unregister_em(struct device *dev) 385 { 386 em_dev_unregister_perf_domain(dev); 387 } 388 #else 389 static inline int dev_pm_opp_of_add_table(struct device *dev) 390 { 391 return -ENOTSUPP; 392 } 393 394 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) 395 { 396 return -ENOTSUPP; 397 } 398 399 static inline void dev_pm_opp_of_remove_table(struct device *dev) 400 { 401 } 402 403 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) 404 { 405 return -ENOTSUPP; 406 } 407 408 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask) 409 { 410 } 411 412 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) 413 { 414 return -ENOTSUPP; 415 } 416 417 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) 418 { 419 return NULL; 420 } 421 422 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) 423 { 424 return NULL; 425 } 426 427 static inline int dev_pm_opp_of_register_em(struct device *dev, 428 struct cpumask *cpus) 429 { 430 return -ENOTSUPP; 431 } 432 433 static inline void dev_pm_opp_of_unregister_em(struct device *dev) 434 { 435 } 436 437 static inline int of_get_required_opp_performance_state(struct device_node *np, int index) 438 { 439 return -ENOTSUPP; 440 } 441 442 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table) 443 { 444 return -ENOTSUPP; 445 } 446 #endif 447 448 #endif /* __LINUX_OPP_H__ */ 449