drm/ast: Only warn about unsupported TX chips on Gen4 and later
[drm/drm-misc.git] / include / linux / pm_opp.h
blob568183e3e641c35d1d4412979197349f38c74cc0
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Generic OPP Interface
5 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
6 * Nishanth Menon
7 * Romit Dasgupta
8 * Kevin Hilman
9 */
11 #ifndef __LINUX_OPP_H__
12 #define __LINUX_OPP_H__
14 #include <linux/energy_model.h>
15 #include <linux/err.h>
16 #include <linux/notifier.h>
18 struct clk;
19 struct cpufreq_frequency_table;
20 struct regulator;
21 struct dev_pm_opp;
22 struct device;
23 struct opp_table;
25 enum dev_pm_opp_event {
26 OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
27 OPP_EVENT_ADJUST_VOLTAGE,
30 /**
31 * struct dev_pm_opp_supply - Power supply voltage/current values
32 * @u_volt: Target voltage in microvolts corresponding to this OPP
33 * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
34 * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
35 * @u_amp: Maximum current drawn by the device in microamperes
36 * @u_watt: Power used by the device in microwatts
38 * This structure stores the voltage/current/power values for a single power
39 * supply.
41 struct dev_pm_opp_supply {
42 unsigned long u_volt;
43 unsigned long u_volt_min;
44 unsigned long u_volt_max;
45 unsigned long u_amp;
46 unsigned long u_watt;
49 typedef int (*config_regulators_t)(struct device *dev,
50 struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
51 struct regulator **regulators, unsigned int count);
53 typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table,
54 struct dev_pm_opp *opp, void *data, bool scaling_down);
56 /**
57 * struct dev_pm_opp_config - Device OPP configuration values
58 * @clk_names: Clk names, NULL terminated array.
59 * @config_clks: Custom set clk helper.
60 * @prop_name: Name to postfix to properties.
61 * @config_regulators: Custom set regulator helper.
62 * @supported_hw: Array of hierarchy of versions to match.
63 * @supported_hw_count: Number of elements in the array.
64 * @regulator_names: Array of pointers to the names of the regulator, NULL terminated.
65 * @required_dev: The required OPP device.
66 * @required_dev_index: The index of the required OPP for the @required_dev.
68 * This structure contains platform specific OPP configurations for the device.
70 struct dev_pm_opp_config {
71 /* NULL terminated */
72 const char * const *clk_names;
73 config_clks_t config_clks;
74 const char *prop_name;
75 config_regulators_t config_regulators;
76 const unsigned int *supported_hw;
77 unsigned int supported_hw_count;
78 const char * const *regulator_names;
79 struct device *required_dev;
80 unsigned int required_dev_index;
83 #define OPP_LEVEL_UNSET U32_MAX
85 /**
86 * struct dev_pm_opp_data - The data to use to initialize an OPP.
87 * @turbo: Flag to indicate whether the OPP is to be marked turbo or not.
88 * @level: The performance level for the OPP. Set level to OPP_LEVEL_UNSET if
89 * level field isn't used.
90 * @freq: The clock rate in Hz for the OPP.
91 * @u_volt: The voltage in uV for the OPP.
93 struct dev_pm_opp_data {
94 bool turbo;
95 unsigned int level;
96 unsigned long freq;
97 unsigned long u_volt;
100 #if defined(CONFIG_PM_OPP)
102 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
103 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
105 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
107 int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies);
109 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
111 unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index);
113 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
115 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
116 unsigned int index);
118 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
120 int dev_pm_opp_get_opp_count(struct device *dev);
121 unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
122 unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
123 unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
124 unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
126 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
127 unsigned long freq,
128 bool available);
130 struct dev_pm_opp *
131 dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
132 u32 index, bool available);
134 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
135 unsigned long *freq);
137 struct dev_pm_opp *dev_pm_opp_find_freq_floor_indexed(struct device *dev,
138 unsigned long *freq, u32 index);
140 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
141 unsigned long *freq);
143 struct dev_pm_opp *dev_pm_opp_find_freq_ceil_indexed(struct device *dev,
144 unsigned long *freq, u32 index);
146 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
147 unsigned int level);
149 struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
150 unsigned int *level);
152 struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev,
153 unsigned int *level);
155 struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
156 unsigned int *bw, int index);
158 struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
159 unsigned int *bw, int index);
161 void dev_pm_opp_put(struct dev_pm_opp *opp);
163 int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp);
165 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
166 void dev_pm_opp_remove_all_dynamic(struct device *dev);
168 int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
169 unsigned long u_volt, unsigned long u_volt_min,
170 unsigned long u_volt_max);
172 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
174 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
176 int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
177 int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
179 int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
180 int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
181 void dev_pm_opp_clear_config(int token);
182 int dev_pm_opp_config_clks_simple(struct device *dev,
183 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
184 bool scaling_down);
186 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);
187 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
188 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
189 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp);
190 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
191 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
192 void dev_pm_opp_remove_table(struct device *dev);
193 void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
194 int dev_pm_opp_sync_regulators(struct device *dev);
195 #else
196 static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
198 return ERR_PTR(-EOPNOTSUPP);
201 static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
203 return ERR_PTR(-EOPNOTSUPP);
206 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
208 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
210 return 0;
213 static inline int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies)
215 return -EOPNOTSUPP;
218 static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
220 return 0;
223 static inline unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
225 return 0;
228 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
230 return 0;
233 static inline
234 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
235 unsigned int index)
237 return 0;
240 static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
242 return false;
245 static inline int dev_pm_opp_get_opp_count(struct device *dev)
247 return 0;
250 static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
252 return 0;
255 static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
257 return 0;
260 static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
262 return 0;
265 static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
267 return 0;
270 static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
271 unsigned long freq, bool available)
273 return ERR_PTR(-EOPNOTSUPP);
276 static inline struct dev_pm_opp *
277 dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
278 u32 index, bool available)
280 return ERR_PTR(-EOPNOTSUPP);
283 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
284 unsigned long *freq)
286 return ERR_PTR(-EOPNOTSUPP);
289 static inline struct dev_pm_opp *
290 dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq, u32 index)
292 return ERR_PTR(-EOPNOTSUPP);
295 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
296 unsigned long *freq)
298 return ERR_PTR(-EOPNOTSUPP);
301 static inline struct dev_pm_opp *
302 dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq, u32 index)
304 return ERR_PTR(-EOPNOTSUPP);
307 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
308 unsigned int level)
310 return ERR_PTR(-EOPNOTSUPP);
313 static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
314 unsigned int *level)
316 return ERR_PTR(-EOPNOTSUPP);
319 static inline struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev,
320 unsigned int *level)
322 return ERR_PTR(-EOPNOTSUPP);
325 static inline struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
326 unsigned int *bw, int index)
328 return ERR_PTR(-EOPNOTSUPP);
331 static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
332 unsigned int *bw, int index)
334 return ERR_PTR(-EOPNOTSUPP);
337 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
339 static inline int
340 dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp)
342 return -EOPNOTSUPP;
345 static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
349 static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
353 static inline int
354 dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
355 unsigned long u_volt, unsigned long u_volt_min,
356 unsigned long u_volt_max)
358 return 0;
361 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
363 return 0;
366 static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
368 return 0;
371 static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
373 return -EOPNOTSUPP;
376 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
378 return -EOPNOTSUPP;
381 static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
383 return -EOPNOTSUPP;
386 static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
388 return -EOPNOTSUPP;
391 static inline void dev_pm_opp_clear_config(int token) {}
393 static inline int dev_pm_opp_config_clks_simple(struct device *dev,
394 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
395 bool scaling_down)
397 return -EOPNOTSUPP;
400 static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
401 struct opp_table *dst_table, struct dev_pm_opp *src_opp)
403 return ERR_PTR(-EOPNOTSUPP);
406 static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
408 return -EOPNOTSUPP;
411 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
413 return -EOPNOTSUPP;
416 static inline int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
418 return -EOPNOTSUPP;
421 static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
423 return -EOPNOTSUPP;
426 static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
428 return -EINVAL;
431 static inline void dev_pm_opp_remove_table(struct device *dev)
435 static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
439 static inline int dev_pm_opp_sync_regulators(struct device *dev)
441 return -EOPNOTSUPP;
444 #endif /* CONFIG_PM_OPP */
446 #if defined(CONFIG_CPU_FREQ) && defined(CONFIG_PM_OPP)
447 int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table);
448 void dev_pm_opp_free_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table);
449 #else
450 static inline int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table)
452 return -EINVAL;
455 static inline void dev_pm_opp_free_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **table)
458 #endif
461 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
462 int dev_pm_opp_of_add_table(struct device *dev);
463 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
464 int devm_pm_opp_of_add_table_indexed(struct device *dev, int index);
465 void dev_pm_opp_of_remove_table(struct device *dev);
466 int devm_pm_opp_of_add_table(struct device *dev);
467 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
468 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
469 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
470 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
471 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
472 int of_get_required_opp_performance_state(struct device_node *np, int index);
473 bool dev_pm_opp_of_has_required_opp(struct device *dev);
474 int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
475 int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
476 int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
477 unsigned long *kHz);
478 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
480 em_dev_unregister_perf_domain(dev);
482 #else
483 static inline int dev_pm_opp_of_add_table(struct device *dev)
485 return -EOPNOTSUPP;
488 static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
490 return -EOPNOTSUPP;
493 static inline int devm_pm_opp_of_add_table_indexed(struct device *dev, int index)
495 return -EOPNOTSUPP;
498 static inline void dev_pm_opp_of_remove_table(struct device *dev)
502 static inline int devm_pm_opp_of_add_table(struct device *dev)
504 return -EOPNOTSUPP;
507 static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
509 return -EOPNOTSUPP;
512 static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
516 static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
518 return -EOPNOTSUPP;
521 static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
523 return NULL;
526 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
528 return NULL;
531 static inline int dev_pm_opp_of_register_em(struct device *dev,
532 struct cpumask *cpus)
534 return -EOPNOTSUPP;
537 static inline void dev_pm_opp_of_unregister_em(struct device *dev)
541 static inline int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
542 unsigned long *kHz)
544 return -EOPNOTSUPP;
547 static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
549 return -EOPNOTSUPP;
552 static inline bool dev_pm_opp_of_has_required_opp(struct device *dev)
554 return false;
557 static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
559 return -EOPNOTSUPP;
561 #endif
563 /* OPP Configuration helpers */
565 static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
566 unsigned long u_volt)
568 struct dev_pm_opp_data data = {
569 .freq = freq,
570 .u_volt = u_volt,
573 return dev_pm_opp_add_dynamic(dev, &data);
576 /* Regulators helpers */
577 static inline int dev_pm_opp_set_regulators(struct device *dev,
578 const char * const names[])
580 struct dev_pm_opp_config config = {
581 .regulator_names = names,
584 return dev_pm_opp_set_config(dev, &config);
587 static inline void dev_pm_opp_put_regulators(int token)
589 dev_pm_opp_clear_config(token);
592 static inline int devm_pm_opp_set_regulators(struct device *dev,
593 const char * const names[])
595 struct dev_pm_opp_config config = {
596 .regulator_names = names,
599 return devm_pm_opp_set_config(dev, &config);
602 /* Supported-hw helpers */
603 static inline int dev_pm_opp_set_supported_hw(struct device *dev,
604 const u32 *versions,
605 unsigned int count)
607 struct dev_pm_opp_config config = {
608 .supported_hw = versions,
609 .supported_hw_count = count,
612 return dev_pm_opp_set_config(dev, &config);
615 static inline void dev_pm_opp_put_supported_hw(int token)
617 dev_pm_opp_clear_config(token);
620 static inline int devm_pm_opp_set_supported_hw(struct device *dev,
621 const u32 *versions,
622 unsigned int count)
624 struct dev_pm_opp_config config = {
625 .supported_hw = versions,
626 .supported_hw_count = count,
629 return devm_pm_opp_set_config(dev, &config);
632 /* clkname helpers */
633 static inline int dev_pm_opp_set_clkname(struct device *dev, const char *name)
635 const char *names[] = { name, NULL };
636 struct dev_pm_opp_config config = {
637 .clk_names = names,
640 return dev_pm_opp_set_config(dev, &config);
643 static inline void dev_pm_opp_put_clkname(int token)
645 dev_pm_opp_clear_config(token);
648 static inline int devm_pm_opp_set_clkname(struct device *dev, const char *name)
650 const char *names[] = { name, NULL };
651 struct dev_pm_opp_config config = {
652 .clk_names = names,
655 return devm_pm_opp_set_config(dev, &config);
658 /* config-regulators helpers */
659 static inline int dev_pm_opp_set_config_regulators(struct device *dev,
660 config_regulators_t helper)
662 struct dev_pm_opp_config config = {
663 .config_regulators = helper,
666 return dev_pm_opp_set_config(dev, &config);
669 static inline void dev_pm_opp_put_config_regulators(int token)
671 dev_pm_opp_clear_config(token);
674 /* prop-name helpers */
675 static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name)
677 struct dev_pm_opp_config config = {
678 .prop_name = name,
681 return dev_pm_opp_set_config(dev, &config);
684 static inline void dev_pm_opp_put_prop_name(int token)
686 dev_pm_opp_clear_config(token);
689 static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
691 return dev_pm_opp_get_freq_indexed(opp, 0);
694 #endif /* __LINUX_OPP_H__ */