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