1
2
3
4
5
6
7
8
9
10
11#ifndef __DRIVER_OPP_H__
12#define __DRIVER_OPP_H__
13
14#include <linux/device.h>
15#include <linux/interconnect.h>
16#include <linux/kernel.h>
17#include <linux/kref.h>
18#include <linux/list.h>
19#include <linux/limits.h>
20#include <linux/pm_opp.h>
21#include <linux/notifier.h>
22
23struct clk;
24struct regulator;
25
26
27extern struct mutex opp_table_lock;
28
29extern struct list_head opp_tables, lazy_opp_tables;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74struct dev_pm_opp {
75 struct list_head node;
76 struct kref kref;
77
78 bool available;
79 bool dynamic;
80 bool turbo;
81 bool suspend;
82 bool removed;
83 unsigned int pstate;
84 unsigned long rate;
85 unsigned int level;
86
87 struct dev_pm_opp_supply *supplies;
88 struct dev_pm_opp_icc_bw *bandwidth;
89
90 unsigned long clock_latency_ns;
91
92 struct dev_pm_opp **required_opps;
93 struct opp_table *opp_table;
94
95 struct device_node *np;
96
97#ifdef CONFIG_DEBUG_FS
98 struct dentry *dentry;
99#endif
100};
101
102
103
104
105
106
107
108
109
110
111struct opp_device {
112 struct list_head node;
113 const struct device *dev;
114
115#ifdef CONFIG_DEBUG_FS
116 struct dentry *dentry;
117#endif
118};
119
120enum opp_table_access {
121 OPP_TABLE_ACCESS_UNKNOWN = 0,
122 OPP_TABLE_ACCESS_EXCLUSIVE = 1,
123 OPP_TABLE_ACCESS_SHARED = 2,
124};
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173struct opp_table {
174 struct list_head node, lazy;
175
176 struct blocking_notifier_head head;
177 struct list_head dev_list;
178 struct list_head opp_list;
179 struct kref kref;
180 struct mutex lock;
181
182 struct device_node *np;
183 unsigned long clock_latency_ns_max;
184
185
186 unsigned int voltage_tolerance_v1;
187
188 unsigned int parsed_static_opps;
189 enum opp_table_access shared_opp;
190 unsigned long current_rate;
191 struct dev_pm_opp *current_opp;
192 struct dev_pm_opp *suspend_opp;
193
194 struct mutex genpd_virt_dev_lock;
195 struct device **genpd_virt_devs;
196 struct opp_table **required_opp_tables;
197 unsigned int required_opp_count;
198
199 unsigned int *supported_hw;
200 unsigned int supported_hw_count;
201 const char *prop_name;
202 struct clk *clk;
203 struct regulator **regulators;
204 int regulator_count;
205 struct icc_path **paths;
206 unsigned int path_count;
207 bool enabled;
208 bool genpd_performance_state;
209 bool is_genpd;
210
211 int (*set_opp)(struct dev_pm_set_opp_data *data);
212 struct dev_pm_opp_supply *sod_supplies;
213 struct dev_pm_set_opp_data *set_opp_data;
214
215#ifdef CONFIG_DEBUG_FS
216 struct dentry *dentry;
217 char dentry_name[NAME_MAX];
218#endif
219};
220
221
222void dev_pm_opp_get(struct dev_pm_opp *opp);
223bool _opp_remove_all_static(struct opp_table *opp_table);
224void _get_opp_table_kref(struct opp_table *opp_table);
225int _get_opp_count(struct opp_table *opp_table);
226struct opp_table *_find_opp_table(struct device *dev);
227struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table);
228struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table);
229void _opp_free(struct dev_pm_opp *opp);
230int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2);
231int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available);
232int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic);
233void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu);
234struct opp_table *_add_opp_table_indexed(struct device *dev, int index, bool getclk);
235void _put_opp_list_kref(struct opp_table *opp_table);
236void _required_opps_available(struct dev_pm_opp *opp, int count);
237
238static inline bool lazy_linking_pending(struct opp_table *opp_table)
239{
240 return unlikely(!list_empty(&opp_table->lazy));
241}
242
243#ifdef CONFIG_OF
244void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index);
245void _of_clear_opp_table(struct opp_table *opp_table);
246struct opp_table *_managed_opp(struct device *dev, int index);
247void _of_opp_free_required_opps(struct opp_table *opp_table,
248 struct dev_pm_opp *opp);
249#else
250static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {}
251static inline void _of_clear_opp_table(struct opp_table *opp_table) {}
252static inline struct opp_table *_managed_opp(struct device *dev, int index) { return NULL; }
253static inline void _of_opp_free_required_opps(struct opp_table *opp_table,
254 struct dev_pm_opp *opp) {}
255#endif
256
257#ifdef CONFIG_DEBUG_FS
258void opp_debug_remove_one(struct dev_pm_opp *opp);
259void opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table);
260void opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table);
261void opp_debug_unregister(struct opp_device *opp_dev, struct opp_table *opp_table);
262#else
263static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {}
264
265static inline void opp_debug_create_one(struct dev_pm_opp *opp,
266 struct opp_table *opp_table) { }
267
268static inline void opp_debug_register(struct opp_device *opp_dev,
269 struct opp_table *opp_table) { }
270
271static inline void opp_debug_unregister(struct opp_device *opp_dev,
272 struct opp_table *opp_table)
273{ }
274#endif
275
276#endif
277