Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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_icc_bw - Interconnect bandwidth values
46 * @avg: Average bandwidth corresponding to this OPP (in icc units)
47 * @peak: Peak bandwidth corresponding to this OPP (in icc units)
48 *
49 * This structure stores the bandwidth values for a single interconnect path.
50 */
51struct dev_pm_opp_icc_bw {
52 u32 avg;
53 u32 peak;
54};
55
56/**
57 * struct dev_pm_opp_info - OPP freq/voltage/current values
58 * @rate: Target clk rate in hz
59 * @supplies: Array of voltage/current values for all power supplies
60 *
61 * This structure stores the freq/voltage/current values for a single OPP.
62 */
63struct dev_pm_opp_info {
64 unsigned long rate;
65 struct dev_pm_opp_supply *supplies;
66};
67
68/**
69 * struct dev_pm_set_opp_data - Set OPP data
70 * @old_opp: Old OPP info
71 * @new_opp: New OPP info
72 * @regulators: Array of regulator pointers
73 * @regulator_count: Number of regulators
74 * @clk: Pointer to clk
75 * @dev: Pointer to the struct device
76 *
77 * This structure contains all information required for setting an OPP.
78 */
79struct dev_pm_set_opp_data {
80 struct dev_pm_opp_info old_opp;
81 struct dev_pm_opp_info new_opp;
82
83 struct regulator **regulators;
84 unsigned int regulator_count;
85 struct clk *clk;
86 struct device *dev;
87};
88
89#if defined(CONFIG_PM_OPP)
90
91struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
92struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index);
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_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
155int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
156void dev_pm_opp_remove_table(struct device *dev);
157void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
158#else
159static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
160{
161 return ERR_PTR(-ENOTSUPP);
162}
163
164static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index)
165{
166 return ERR_PTR(-ENOTSUPP);
167}
168
169static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
170
171static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
172{
173 return 0;
174}
175
176static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
177{
178 return 0;
179}
180
181static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
182{
183 return 0;
184}
185
186static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
187{
188 return false;
189}
190
191static inline int dev_pm_opp_get_opp_count(struct device *dev)
192{
193 return 0;
194}
195
196static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
197{
198 return 0;
199}
200
201static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
202{
203 return 0;
204}
205
206static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
207{
208 return 0;
209}
210
211static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
212{
213 return 0;
214}
215
216static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
217 unsigned long freq, bool available)
218{
219 return ERR_PTR(-ENOTSUPP);
220}
221
222static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
223 unsigned int level)
224{
225 return ERR_PTR(-ENOTSUPP);
226}
227
228static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
229 unsigned long *freq)
230{
231 return ERR_PTR(-ENOTSUPP);
232}
233
234static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
235 unsigned long u_volt)
236{
237 return ERR_PTR(-ENOTSUPP);
238}
239
240static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
241 unsigned long *freq)
242{
243 return ERR_PTR(-ENOTSUPP);
244}
245
246static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
247
248static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
249 unsigned long u_volt)
250{
251 return -ENOTSUPP;
252}
253
254static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
255{
256}
257
258static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
259{
260}
261
262static inline int
263dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
264 unsigned long u_volt, unsigned long u_volt_min,
265 unsigned long u_volt_max)
266{
267 return 0;
268}
269
270static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
271{
272 return 0;
273}
274
275static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
276{
277 return 0;
278}
279
280static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
281{
282 return -ENOTSUPP;
283}
284
285static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
286{
287 return -ENOTSUPP;
288}
289
290static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
291 const u32 *versions,
292 unsigned int count)
293{
294 return ERR_PTR(-ENOTSUPP);
295}
296
297static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
298
299static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
300 int (*set_opp)(struct dev_pm_set_opp_data *data))
301{
302 return ERR_PTR(-ENOTSUPP);
303}
304
305static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
306
307static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
308{
309 return ERR_PTR(-ENOTSUPP);
310}
311
312static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
313
314static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
315{
316 return ERR_PTR(-ENOTSUPP);
317}
318
319static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
320
321static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name)
322{
323 return ERR_PTR(-ENOTSUPP);
324}
325
326static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
327
328static inline struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs)
329{
330 return ERR_PTR(-ENOTSUPP);
331}
332
333static inline void dev_pm_opp_detach_genpd(struct opp_table *opp_table) {}
334
335static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate)
336{
337 return -ENOTSUPP;
338}
339
340static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
341{
342 return -ENOTSUPP;
343}
344
345static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
346{
347 return -ENOTSUPP;
348}
349
350static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
351{
352 return -EINVAL;
353}
354
355static inline void dev_pm_opp_remove_table(struct device *dev)
356{
357}
358
359static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
360{
361}
362
363#endif /* CONFIG_PM_OPP */
364
365#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
366int dev_pm_opp_of_add_table(struct device *dev);
367int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
368void dev_pm_opp_of_remove_table(struct device *dev);
369int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
370void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
371int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
372struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
373struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
374int of_get_required_opp_performance_state(struct device_node *np, int index);
375int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
376void dev_pm_opp_of_register_em(struct cpumask *cpus);
377#else
378static inline int dev_pm_opp_of_add_table(struct device *dev)
379{
380 return -ENOTSUPP;
381}
382
383static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
384{
385 return -ENOTSUPP;
386}
387
388static inline void dev_pm_opp_of_remove_table(struct device *dev)
389{
390}
391
392static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
393{
394 return -ENOTSUPP;
395}
396
397static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
398{
399}
400
401static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
402{
403 return -ENOTSUPP;
404}
405
406static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
407{
408 return NULL;
409}
410
411static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
412{
413 return NULL;
414}
415
416static inline void dev_pm_opp_of_register_em(struct cpumask *cpus)
417{
418}
419
420static inline int of_get_required_opp_performance_state(struct device_node *np, int index)
421{
422 return -ENOTSUPP;
423}
424
425static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
426{
427 return -ENOTSUPP;
428}
429#endif
430
431#endif /* __LINUX_OPP_H__ */