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