at v5.11 13 kB view raw
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 18struct clk; 19struct regulator; 20struct dev_pm_opp; 21struct device; 22struct opp_table; 23 24enum 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 */ 38struct 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 */ 52struct 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 */ 64struct 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 */ 80struct 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 92struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); 93void dev_pm_opp_put_opp_table(struct opp_table *opp_table); 94 95unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp); 96 97unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp); 98 99unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp); 100 101bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp); 102 103int dev_pm_opp_get_opp_count(struct device *dev); 104unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev); 105unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev); 106unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev); 107unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev); 108 109struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, 110 unsigned long freq, 111 bool available); 112struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, 113 unsigned int level); 114 115struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, 116 unsigned long *freq); 117struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, 118 unsigned long u_volt); 119 120struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, 121 unsigned long *freq); 122void dev_pm_opp_put(struct dev_pm_opp *opp); 123 124int dev_pm_opp_add(struct device *dev, unsigned long freq, 125 unsigned long u_volt); 126void dev_pm_opp_remove(struct device *dev, unsigned long freq); 127void dev_pm_opp_remove_all_dynamic(struct device *dev); 128 129int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, 130 unsigned long u_volt, unsigned long u_volt_min, 131 unsigned long u_volt_max); 132 133int dev_pm_opp_enable(struct device *dev, unsigned long freq); 134 135int dev_pm_opp_disable(struct device *dev, unsigned long freq); 136 137int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb); 138int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb); 139 140struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count); 141void dev_pm_opp_put_supported_hw(struct opp_table *opp_table); 142struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name); 143void dev_pm_opp_put_prop_name(struct opp_table *opp_table); 144struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count); 145void dev_pm_opp_put_regulators(struct opp_table *opp_table); 146struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name); 147void dev_pm_opp_put_clkname(struct opp_table *opp_table); 148struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); 149void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); 150struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs); 151void dev_pm_opp_detach_genpd(struct opp_table *opp_table); 152int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate); 153int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); 154int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp); 155int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); 156int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); 157void dev_pm_opp_remove_table(struct device *dev); 158void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask); 159#else 160static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) 161{ 162 return ERR_PTR(-ENOTSUPP); 163} 164 165static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index) 166{ 167 return ERR_PTR(-ENOTSUPP); 168} 169 170static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} 171 172static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) 173{ 174 return 0; 175} 176 177static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp) 178{ 179 return 0; 180} 181 182static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) 183{ 184 return 0; 185} 186 187static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp) 188{ 189 return false; 190} 191 192static inline int dev_pm_opp_get_opp_count(struct device *dev) 193{ 194 return 0; 195} 196 197static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev) 198{ 199 return 0; 200} 201 202static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) 203{ 204 return 0; 205} 206 207static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev) 208{ 209 return 0; 210} 211 212static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) 213{ 214 return 0; 215} 216 217static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, 218 unsigned long freq, bool available) 219{ 220 return ERR_PTR(-ENOTSUPP); 221} 222 223static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, 224 unsigned int level) 225{ 226 return ERR_PTR(-ENOTSUPP); 227} 228 229static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, 230 unsigned long *freq) 231{ 232 return ERR_PTR(-ENOTSUPP); 233} 234 235static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev, 236 unsigned long u_volt) 237{ 238 return ERR_PTR(-ENOTSUPP); 239} 240 241static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, 242 unsigned long *freq) 243{ 244 return ERR_PTR(-ENOTSUPP); 245} 246 247static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} 248 249static inline int dev_pm_opp_add(struct device *dev, unsigned long freq, 250 unsigned long u_volt) 251{ 252 return -ENOTSUPP; 253} 254 255static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq) 256{ 257} 258 259static inline void dev_pm_opp_remove_all_dynamic(struct device *dev) 260{ 261} 262 263static inline int 264dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, 265 unsigned long u_volt, unsigned long u_volt_min, 266 unsigned long u_volt_max) 267{ 268 return 0; 269} 270 271static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq) 272{ 273 return 0; 274} 275 276static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq) 277{ 278 return 0; 279} 280 281static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb) 282{ 283 return -ENOTSUPP; 284} 285 286static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb) 287{ 288 return -ENOTSUPP; 289} 290 291static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, 292 const u32 *versions, 293 unsigned int count) 294{ 295 return ERR_PTR(-ENOTSUPP); 296} 297 298static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {} 299 300static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, 301 int (*set_opp)(struct dev_pm_set_opp_data *data)) 302{ 303 return ERR_PTR(-ENOTSUPP); 304} 305 306static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {} 307 308static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) 309{ 310 return ERR_PTR(-ENOTSUPP); 311} 312 313static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {} 314 315static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count) 316{ 317 return ERR_PTR(-ENOTSUPP); 318} 319 320static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {} 321 322static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name) 323{ 324 return ERR_PTR(-ENOTSUPP); 325} 326 327static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {} 328 329static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs) 330{ 331 return ERR_PTR(-ENOTSUPP); 332} 333 334static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {} 335 336static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate) 337{ 338 return -ENOTSUPP; 339} 340 341static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) 342{ 343 return -ENOTSUPP; 344} 345 346static inline int dev_pm_opp_set_bw(struct device *dev, struct dev_pm_opp *opp) 347{ 348 return -EOPNOTSUPP; 349} 350 351static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask) 352{ 353 return -ENOTSUPP; 354} 355 356static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) 357{ 358 return -EINVAL; 359} 360 361static inline void dev_pm_opp_remove_table(struct device *dev) 362{ 363} 364 365static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask) 366{ 367} 368 369#endif /* CONFIG_PM_OPP */ 370 371#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) 372int dev_pm_opp_of_add_table(struct device *dev); 373int dev_pm_opp_of_add_table_indexed(struct device *dev, int index); 374void dev_pm_opp_of_remove_table(struct device *dev); 375int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); 376void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask); 377int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); 378struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); 379struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp); 380int of_get_required_opp_performance_state(struct device_node *np, int index); 381int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table); 382int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus); 383static inline void dev_pm_opp_of_unregister_em(struct device *dev) 384{ 385 em_dev_unregister_perf_domain(dev); 386} 387#else 388static inline int dev_pm_opp_of_add_table(struct device *dev) 389{ 390 return -ENOTSUPP; 391} 392 393static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) 394{ 395 return -ENOTSUPP; 396} 397 398static inline void dev_pm_opp_of_remove_table(struct device *dev) 399{ 400} 401 402static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) 403{ 404 return -ENOTSUPP; 405} 406 407static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask) 408{ 409} 410 411static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) 412{ 413 return -ENOTSUPP; 414} 415 416static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) 417{ 418 return NULL; 419} 420 421static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) 422{ 423 return NULL; 424} 425 426static inline int dev_pm_opp_of_register_em(struct device *dev, 427 struct cpumask *cpus) 428{ 429 return -ENOTSUPP; 430} 431 432static inline void dev_pm_opp_of_unregister_em(struct device *dev) 433{ 434} 435 436static inline int of_get_required_opp_performance_state(struct device_node *np, int index) 437{ 438 return -ENOTSUPP; 439} 440 441static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table) 442{ 443 return -ENOTSUPP; 444} 445#endif 446 447#endif /* __LINUX_OPP_H__ */