| 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/cleanup.h> |
| 15 | #include <linux/energy_model.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/notifier.h> |
| 18 | |
| 19 | struct clk; |
| 20 | struct cpufreq_frequency_table; |
| 21 | struct regulator; |
| 22 | struct dev_pm_opp; |
| 23 | struct device; |
| 24 | struct opp_table; |
| 25 | |
| 26 | enum dev_pm_opp_event { |
| 27 | OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE, |
| 28 | OPP_EVENT_ADJUST_VOLTAGE, |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * struct dev_pm_opp_supply - Power supply voltage/current values |
| 33 | * @u_volt: Target voltage in microvolts corresponding to this OPP |
| 34 | * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP |
| 35 | * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP |
| 36 | * @u_amp: Maximum current drawn by the device in microamperes |
| 37 | * @u_watt: Power used by the device in microwatts |
| 38 | * |
| 39 | * This structure stores the voltage/current/power values for a single power |
| 40 | * supply. |
| 41 | */ |
| 42 | struct dev_pm_opp_supply { |
| 43 | unsigned long u_volt; |
| 44 | unsigned long u_volt_min; |
| 45 | unsigned long u_volt_max; |
| 46 | unsigned long u_amp; |
| 47 | unsigned long u_watt; |
| 48 | }; |
| 49 | |
| 50 | typedef int (*config_regulators_t)(struct device *dev, |
| 51 | struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp, |
| 52 | struct regulator **regulators, unsigned int count); |
| 53 | |
| 54 | typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table, |
| 55 | struct dev_pm_opp *opp, void *data, bool scaling_down); |
| 56 | |
| 57 | /** |
| 58 | * struct dev_pm_opp_config - Device OPP configuration values |
| 59 | * @clk_names: Clk names, NULL terminated array. |
| 60 | * @config_clks: Custom set clk helper. |
| 61 | * @prop_name: Name to postfix to properties. |
| 62 | * @config_regulators: Custom set regulator helper. |
| 63 | * @supported_hw: Array of hierarchy of versions to match. |
| 64 | * @supported_hw_count: Number of elements in the array. |
| 65 | * @regulator_names: Array of pointers to the names of the regulator, NULL terminated. |
| 66 | * @required_dev: The required OPP device. |
| 67 | * @required_dev_index: The index of the required OPP for the @required_dev. |
| 68 | * |
| 69 | * This structure contains platform specific OPP configurations for the device. |
| 70 | */ |
| 71 | struct dev_pm_opp_config { |
| 72 | /* NULL terminated */ |
| 73 | const char * const *clk_names; |
| 74 | config_clks_t config_clks; |
| 75 | const char *prop_name; |
| 76 | config_regulators_t config_regulators; |
| 77 | const unsigned int *supported_hw; |
| 78 | unsigned int supported_hw_count; |
| 79 | const char * const *regulator_names; |
| 80 | struct device *required_dev; |
| 81 | unsigned int required_dev_index; |
| 82 | }; |
| 83 | |
| 84 | #define OPP_LEVEL_UNSET U32_MAX |
| 85 | |
| 86 | /** |
| 87 | * struct dev_pm_opp_data - The data to use to initialize an OPP. |
| 88 | * @turbo: Flag to indicate whether the OPP is to be marked turbo or not. |
| 89 | * @level: The performance level for the OPP. Set level to OPP_LEVEL_UNSET if |
| 90 | * level field isn't used. |
| 91 | * @freq: The clock rate in Hz for the OPP. |
| 92 | * @u_volt: The voltage in uV for the OPP. |
| 93 | */ |
| 94 | struct dev_pm_opp_data { |
| 95 | bool turbo; |
| 96 | unsigned int level; |
| 97 | unsigned long freq; |
| 98 | unsigned long u_volt; |
| 99 | }; |
| 100 | |
| 101 | #if defined(CONFIG_PM_OPP) |
| 102 | |
| 103 | struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); |
| 104 | struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table); |
| 105 | void dev_pm_opp_put_opp_table(struct opp_table *opp_table); |
| 106 | |
| 107 | unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index); |
| 108 | |
| 109 | unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp); |
| 110 | |
| 111 | int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies); |
| 112 | |
| 113 | unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp); |
| 114 | |
| 115 | unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index); |
| 116 | |
| 117 | unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp); |
| 118 | |
| 119 | unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp, |
| 120 | unsigned int index); |
| 121 | |
| 122 | bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp); |
| 123 | |
| 124 | int dev_pm_opp_get_opp_count(struct device *dev); |
| 125 | unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev); |
| 126 | unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev); |
| 127 | unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev); |
| 128 | unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev); |
| 129 | |
| 130 | struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, |
| 131 | unsigned long freq, |
| 132 | bool available); |
| 133 | |
| 134 | struct dev_pm_opp * |
| 135 | dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq, |
| 136 | u32 index, bool available); |
| 137 | |
| 138 | struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, |
| 139 | unsigned long *freq); |
| 140 | |
| 141 | struct dev_pm_opp *dev_pm_opp_find_freq_floor_indexed(struct device *dev, |
| 142 | unsigned long *freq, u32 index); |
| 143 | |
| 144 | struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, |
| 145 | unsigned long *freq); |
| 146 | |
| 147 | struct dev_pm_opp *dev_pm_opp_find_freq_ceil_indexed(struct device *dev, |
| 148 | unsigned long *freq, u32 index); |
| 149 | |
| 150 | struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, |
| 151 | unsigned int level); |
| 152 | |
| 153 | struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev, |
| 154 | unsigned int *level); |
| 155 | |
| 156 | struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev, |
| 157 | unsigned int *level); |
| 158 | |
| 159 | struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, |
| 160 | unsigned int *bw, int index); |
| 161 | |
| 162 | struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, |
| 163 | unsigned int *bw, int index); |
| 164 | |
| 165 | struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp); |
| 166 | void dev_pm_opp_put(struct dev_pm_opp *opp); |
| 167 | |
| 168 | int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp); |
| 169 | |
| 170 | void dev_pm_opp_remove(struct device *dev, unsigned long freq); |
| 171 | void dev_pm_opp_remove_all_dynamic(struct device *dev); |
| 172 | |
| 173 | int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, |
| 174 | unsigned long u_volt, unsigned long u_volt_min, |
| 175 | unsigned long u_volt_max); |
| 176 | |
| 177 | int dev_pm_opp_enable(struct device *dev, unsigned long freq); |
| 178 | |
| 179 | int dev_pm_opp_disable(struct device *dev, unsigned long freq); |
| 180 | |
| 181 | int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb); |
| 182 | int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb); |
| 183 | |
| 184 | int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config); |
| 185 | int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config); |
| 186 | void dev_pm_opp_clear_config(int token); |
| 187 | int dev_pm_opp_config_clks_simple(struct device *dev, |
| 188 | struct opp_table *opp_table, struct dev_pm_opp *opp, void *data, |
| 189 | bool scaling_down); |
| 190 | |
| 191 | struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, struct opp_table *dst_table, struct dev_pm_opp *src_opp); |
| 192 | int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate); |
| 193 | int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); |
| 194 | int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp); |
| 195 | int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); |
| 196 | int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); |
| 197 | void dev_pm_opp_remove_table(struct device *dev); |
| 198 | void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask); |
| 199 | int dev_pm_opp_sync_regulators(struct device *dev); |
| 200 | |
| 201 | #else |
| 202 | static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) |
| 203 | { |
| 204 | return ERR_PTR(-EOPNOTSUPP); |
| 205 | } |
| 206 | |
| 207 | static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index) |
| 208 | { |
| 209 | return ERR_PTR(-EOPNOTSUPP); |
| 210 | } |
| 211 | |
| 212 | static inline struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) |
| 213 | { |
| 214 | return opp_table; |
| 215 | } |
| 216 | |
| 217 | static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} |
| 218 | |
| 219 | static inline unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index) |
| 220 | { |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) |
| 225 | { |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | static inline int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies) |
| 230 | { |
| 231 | return -EOPNOTSUPP; |
| 232 | } |
| 233 | |
| 234 | static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp) |
| 235 | { |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static inline unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index) |
| 240 | { |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) |
| 245 | { |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static inline |
| 250 | unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp, |
| 251 | unsigned int index) |
| 252 | { |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp) |
| 257 | { |
| 258 | return false; |
| 259 | } |
| 260 | |
| 261 | static inline int dev_pm_opp_get_opp_count(struct device *dev) |
| 262 | { |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev) |
| 267 | { |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) |
| 272 | { |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev) |
| 277 | { |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) |
| 282 | { |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, |
| 287 | unsigned long freq, bool available) |
| 288 | { |
| 289 | return ERR_PTR(-EOPNOTSUPP); |
| 290 | } |
| 291 | |
| 292 | static inline struct dev_pm_opp * |
| 293 | dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq, |
| 294 | u32 index, bool available) |
| 295 | { |
| 296 | return ERR_PTR(-EOPNOTSUPP); |
| 297 | } |
| 298 | |
| 299 | static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, |
| 300 | unsigned long *freq) |
| 301 | { |
| 302 | return ERR_PTR(-EOPNOTSUPP); |
| 303 | } |
| 304 | |
| 305 | static inline struct dev_pm_opp * |
| 306 | dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq, u32 index) |
| 307 | { |
| 308 | return ERR_PTR(-EOPNOTSUPP); |
| 309 | } |
| 310 | |
| 311 | static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, |
| 312 | unsigned long *freq) |
| 313 | { |
| 314 | return ERR_PTR(-EOPNOTSUPP); |
| 315 | } |
| 316 | |
| 317 | static inline struct dev_pm_opp * |
| 318 | dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq, u32 index) |
| 319 | { |
| 320 | return ERR_PTR(-EOPNOTSUPP); |
| 321 | } |
| 322 | |
| 323 | static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, |
| 324 | unsigned int level) |
| 325 | { |
| 326 | return ERR_PTR(-EOPNOTSUPP); |
| 327 | } |
| 328 | |
| 329 | static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev, |
| 330 | unsigned int *level) |
| 331 | { |
| 332 | return ERR_PTR(-EOPNOTSUPP); |
| 333 | } |
| 334 | |
| 335 | static inline struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev, |
| 336 | unsigned int *level) |
| 337 | { |
| 338 | return ERR_PTR(-EOPNOTSUPP); |
| 339 | } |
| 340 | |
| 341 | static inline struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, |
| 342 | unsigned int *bw, int index) |
| 343 | { |
| 344 | return ERR_PTR(-EOPNOTSUPP); |
| 345 | } |
| 346 | |
| 347 | static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, |
| 348 | unsigned int *bw, int index) |
| 349 | { |
| 350 | return ERR_PTR(-EOPNOTSUPP); |
| 351 | } |
| 352 | |
| 353 | static inline struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp) |
| 354 | { |
| 355 | return opp; |
| 356 | } |
| 357 | |
| 358 | static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} |
| 359 | |
| 360 | static inline int |
| 361 | dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp) |
| 362 | { |
| 363 | return -EOPNOTSUPP; |
| 364 | } |
| 365 | |
| 366 | static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq) |
| 367 | { |
| 368 | } |
| 369 | |
| 370 | static inline void dev_pm_opp_remove_all_dynamic(struct device *dev) |
| 371 | { |
| 372 | } |
| 373 | |
| 374 | static inline int |
| 375 | dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, |
| 376 | unsigned long u_volt, unsigned long u_volt_min, |
| 377 | unsigned long u_volt_max) |
| 378 | { |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq) |
| 383 | { |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq) |
| 388 | { |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb) |
| 393 | { |
| 394 | return -EOPNOTSUPP; |
| 395 | } |
| 396 | |
| 397 | static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb) |
| 398 | { |
| 399 | return -EOPNOTSUPP; |
| 400 | } |
| 401 | |
| 402 | static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) |
| 403 | { |
| 404 | return -EOPNOTSUPP; |
| 405 | } |
| 406 | |
| 407 | static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) |
| 408 | { |
| 409 | return -EOPNOTSUPP; |
| 410 | } |
| 411 | |
| 412 | static inline void dev_pm_opp_clear_config(int token) {} |
| 413 | |
| 414 | static inline int dev_pm_opp_config_clks_simple(struct device *dev, |
| 415 | struct opp_table *opp_table, struct dev_pm_opp *opp, void *data, |
| 416 | bool scaling_down) |
| 417 | { |
| 418 | return -EOPNOTSUPP; |
| 419 | } |
| 420 | |
| 421 | static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, |
| 422 | struct opp_table *dst_table, struct dev_pm_opp *src_opp) |
| 423 | { |
| 424 | return ERR_PTR(-EOPNOTSUPP); |
| 425 | } |
| 426 | |
| 427 | static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate) |
| 428 | { |
| 429 | return -EOPNOTSUPP; |
| 430 | } |
| 431 | |
| 432 | static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) |
| 433 | { |
| 434 | return -EOPNOTSUPP; |
| 435 | } |
| 436 | |
| 437 | static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp) |
| 438 | { |
| 439 | return -EOPNOTSUPP; |
| 440 | } |
| 441 | |
| 442 | static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask) |
| 443 | { |
| 444 | return -EOPNOTSUPP; |
| 445 | } |
| 446 | |
| 447 | static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) |
| 448 | { |
| 449 | return -EINVAL; |
| 450 | } |
| 451 | |
| 452 | static inline void dev_pm_opp_remove_table(struct device *dev) |
| 453 | { |
| 454 | } |
| 455 | |
| 456 | static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask) |
| 457 | { |
| 458 | } |
| 459 | |
| 460 | static inline int dev_pm_opp_sync_regulators(struct device *dev) |
| 461 | { |
| 462 | return -EOPNOTSUPP; |
| 463 | } |
| 464 | |
| 465 | #endif /* CONFIG_PM_OPP */ |
| 466 | |
| 467 | #if defined(CONFIG_CPU_FREQ) && defined(CONFIG_PM_OPP) |
| 468 | int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table); |
| 469 | void dev_pm_opp_free_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table); |
| 470 | #else |
| 471 | static inline int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table) |
| 472 | { |
| 473 | return -EINVAL; |
| 474 | } |
| 475 | |
| 476 | static inline void dev_pm_opp_free_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table) |
| 477 | { |
| 478 | } |
| 479 | #endif |
| 480 | |
| 481 | |
| 482 | #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) |
| 483 | int dev_pm_opp_of_add_table(struct device *dev); |
| 484 | int dev_pm_opp_of_add_table_indexed(struct device *dev, int index); |
| 485 | int devm_pm_opp_of_add_table_indexed(struct device *dev, int index); |
| 486 | void dev_pm_opp_of_remove_table(struct device *dev); |
| 487 | int devm_pm_opp_of_add_table(struct device *dev); |
| 488 | int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); |
| 489 | void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask); |
| 490 | int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); |
| 491 | struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); |
| 492 | struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp); |
| 493 | int of_get_required_opp_performance_state(struct device_node *np, int index); |
| 494 | bool dev_pm_opp_of_has_required_opp(struct device *dev); |
| 495 | int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table); |
| 496 | int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus); |
| 497 | int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW, |
| 498 | unsigned long *kHz); |
| 499 | static inline void dev_pm_opp_of_unregister_em(struct device *dev) |
| 500 | { |
| 501 | em_dev_unregister_perf_domain(dev); |
| 502 | } |
| 503 | #else |
| 504 | static inline int dev_pm_opp_of_add_table(struct device *dev) |
| 505 | { |
| 506 | return -EOPNOTSUPP; |
| 507 | } |
| 508 | |
| 509 | static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) |
| 510 | { |
| 511 | return -EOPNOTSUPP; |
| 512 | } |
| 513 | |
| 514 | static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index) |
| 515 | { |
| 516 | return -EOPNOTSUPP; |
| 517 | } |
| 518 | |
| 519 | static inline void dev_pm_opp_of_remove_table(struct device *dev) |
| 520 | { |
| 521 | } |
| 522 | |
| 523 | static inline int devm_pm_opp_of_add_table(struct device *dev) |
| 524 | { |
| 525 | return -EOPNOTSUPP; |
| 526 | } |
| 527 | |
| 528 | static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) |
| 529 | { |
| 530 | return -EOPNOTSUPP; |
| 531 | } |
| 532 | |
| 533 | static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask) |
| 534 | { |
| 535 | } |
| 536 | |
| 537 | static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) |
| 538 | { |
| 539 | return -EOPNOTSUPP; |
| 540 | } |
| 541 | |
| 542 | static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) |
| 543 | { |
| 544 | return NULL; |
| 545 | } |
| 546 | |
| 547 | static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) |
| 548 | { |
| 549 | return NULL; |
| 550 | } |
| 551 | |
| 552 | static inline int dev_pm_opp_of_register_em(struct device *dev, |
| 553 | struct cpumask *cpus) |
| 554 | { |
| 555 | return -EOPNOTSUPP; |
| 556 | } |
| 557 | |
| 558 | static inline void dev_pm_opp_of_unregister_em(struct device *dev) |
| 559 | { |
| 560 | } |
| 561 | |
| 562 | static inline int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW, |
| 563 | unsigned long *kHz) |
| 564 | { |
| 565 | return -EOPNOTSUPP; |
| 566 | } |
| 567 | |
| 568 | static inline int of_get_required_opp_performance_state(struct device_node *np, int index) |
| 569 | { |
| 570 | return -EOPNOTSUPP; |
| 571 | } |
| 572 | |
| 573 | static inline bool dev_pm_opp_of_has_required_opp(struct device *dev) |
| 574 | { |
| 575 | return false; |
| 576 | } |
| 577 | |
| 578 | static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table) |
| 579 | { |
| 580 | return -EOPNOTSUPP; |
| 581 | } |
| 582 | #endif |
| 583 | |
| 584 | /* Scope based cleanup macro for OPP reference counting */ |
| 585 | DEFINE_FREE(put_opp, struct dev_pm_opp *, if (!IS_ERR_OR_NULL(_T)) dev_pm_opp_put(_T)) |
| 586 | |
| 587 | /* Scope based cleanup macro for OPP table reference counting */ |
| 588 | DEFINE_FREE(put_opp_table, struct opp_table *, if (!IS_ERR_OR_NULL(_T)) dev_pm_opp_put_opp_table(_T)) |
| 589 | |
| 590 | /* OPP Configuration helpers */ |
| 591 | |
| 592 | static inline int dev_pm_opp_add(struct device *dev, unsigned long freq, |
| 593 | unsigned long u_volt) |
| 594 | { |
| 595 | struct dev_pm_opp_data data = { |
| 596 | .freq = freq, |
| 597 | .u_volt = u_volt, |
| 598 | }; |
| 599 | |
| 600 | return dev_pm_opp_add_dynamic(dev, opp: &data); |
| 601 | } |
| 602 | |
| 603 | /* Regulators helpers */ |
| 604 | static inline int dev_pm_opp_set_regulators(struct device *dev, |
| 605 | const char * const names[]) |
| 606 | { |
| 607 | struct dev_pm_opp_config config = { |
| 608 | .regulator_names = names, |
| 609 | }; |
| 610 | |
| 611 | return dev_pm_opp_set_config(dev, config: &config); |
| 612 | } |
| 613 | |
| 614 | static inline void dev_pm_opp_put_regulators(int token) |
| 615 | { |
| 616 | dev_pm_opp_clear_config(token); |
| 617 | } |
| 618 | |
| 619 | static inline int devm_pm_opp_set_regulators(struct device *dev, |
| 620 | const char * const names[]) |
| 621 | { |
| 622 | struct dev_pm_opp_config config = { |
| 623 | .regulator_names = names, |
| 624 | }; |
| 625 | |
| 626 | return devm_pm_opp_set_config(dev, config: &config); |
| 627 | } |
| 628 | |
| 629 | /* Supported-hw helpers */ |
| 630 | static inline int dev_pm_opp_set_supported_hw(struct device *dev, |
| 631 | const u32 *versions, |
| 632 | unsigned int count) |
| 633 | { |
| 634 | struct dev_pm_opp_config config = { |
| 635 | .supported_hw = versions, |
| 636 | .supported_hw_count = count, |
| 637 | }; |
| 638 | |
| 639 | return dev_pm_opp_set_config(dev, config: &config); |
| 640 | } |
| 641 | |
| 642 | static inline void dev_pm_opp_put_supported_hw(int token) |
| 643 | { |
| 644 | dev_pm_opp_clear_config(token); |
| 645 | } |
| 646 | |
| 647 | static inline int devm_pm_opp_set_supported_hw(struct device *dev, |
| 648 | const u32 *versions, |
| 649 | unsigned int count) |
| 650 | { |
| 651 | struct dev_pm_opp_config config = { |
| 652 | .supported_hw = versions, |
| 653 | .supported_hw_count = count, |
| 654 | }; |
| 655 | |
| 656 | return devm_pm_opp_set_config(dev, config: &config); |
| 657 | } |
| 658 | |
| 659 | /* clkname helpers */ |
| 660 | static inline int dev_pm_opp_set_clkname(struct device *dev, const char *name) |
| 661 | { |
| 662 | const char *names[] = { name, NULL }; |
| 663 | struct dev_pm_opp_config config = { |
| 664 | .clk_names = names, |
| 665 | }; |
| 666 | |
| 667 | return dev_pm_opp_set_config(dev, config: &config); |
| 668 | } |
| 669 | |
| 670 | static inline void dev_pm_opp_put_clkname(int token) |
| 671 | { |
| 672 | dev_pm_opp_clear_config(token); |
| 673 | } |
| 674 | |
| 675 | static inline int devm_pm_opp_set_clkname(struct device *dev, const char *name) |
| 676 | { |
| 677 | const char *names[] = { name, NULL }; |
| 678 | struct dev_pm_opp_config config = { |
| 679 | .clk_names = names, |
| 680 | }; |
| 681 | |
| 682 | return devm_pm_opp_set_config(dev, config: &config); |
| 683 | } |
| 684 | |
| 685 | /* config-regulators helpers */ |
| 686 | static inline int dev_pm_opp_set_config_regulators(struct device *dev, |
| 687 | config_regulators_t helper) |
| 688 | { |
| 689 | struct dev_pm_opp_config config = { |
| 690 | .config_regulators = helper, |
| 691 | }; |
| 692 | |
| 693 | return dev_pm_opp_set_config(dev, config: &config); |
| 694 | } |
| 695 | |
| 696 | static inline void dev_pm_opp_put_config_regulators(int token) |
| 697 | { |
| 698 | dev_pm_opp_clear_config(token); |
| 699 | } |
| 700 | |
| 701 | /* prop-name helpers */ |
| 702 | static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name) |
| 703 | { |
| 704 | struct dev_pm_opp_config config = { |
| 705 | .prop_name = name, |
| 706 | }; |
| 707 | |
| 708 | return dev_pm_opp_set_config(dev, config: &config); |
| 709 | } |
| 710 | |
| 711 | static inline void dev_pm_opp_put_prop_name(int token) |
| 712 | { |
| 713 | dev_pm_opp_clear_config(token); |
| 714 | } |
| 715 | |
| 716 | static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp) |
| 717 | { |
| 718 | return dev_pm_opp_get_freq_indexed(opp, index: 0); |
| 719 | } |
| 720 | |
| 721 | static inline int dev_pm_opp_set_level(struct device *dev, unsigned int level) |
| 722 | { |
| 723 | struct dev_pm_opp *opp __free(put_opp) = dev_pm_opp_find_level_exact(dev, level); |
| 724 | |
| 725 | if (IS_ERR(ptr: opp)) |
| 726 | return PTR_ERR(ptr: opp); |
| 727 | |
| 728 | return dev_pm_opp_set_opp(dev, opp); |
| 729 | } |
| 730 | |
| 731 | #endif /* __LINUX_OPP_H__ */ |
| 732 | |