]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - include/linux/regulator/consumer.h
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux...
[karo-tx-linux.git] / include / linux / regulator / consumer.h
1 /*
2  * consumer.h -- SoC Regulator consumer support.
3  *
4  * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
5  * Copyright (C) 2013 Freescale Semiconductor, Inc.
6  *
7  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  *
13  * Regulator Consumer Interface.
14  *
15  * A Power Management Regulator framework for SoC based devices.
16  * Features:-
17  *   o Voltage and current level control.
18  *   o Operating mode control.
19  *   o Regulator status.
20  *   o sysfs entries for showing client devices and status
21  *
22  * EXPERIMENTAL FEATURES:
23  *   Dynamic Regulator operating Mode Switching (DRMS) - allows regulators
24  *   to use most efficient operating mode depending upon voltage and load and
25  *   is transparent to client drivers.
26  *
27  *   e.g. Devices x,y,z share regulator r. Device x and y draw 20mA each during
28  *   IO and 1mA at idle. Device z draws 100mA when under load and 5mA when
29  *   idling. Regulator r has > 90% efficiency in NORMAL mode at loads > 100mA
30  *   but this drops rapidly to 60% when below 100mA. Regulator r has > 90%
31  *   efficiency in IDLE mode at loads < 10mA. Thus regulator r will operate
32  *   in normal mode for loads > 10mA and in IDLE mode for load <= 10mA.
33  *
34  */
35
36 #ifndef __LINUX_REGULATOR_CONSUMER_H_
37 #define __LINUX_REGULATOR_CONSUMER_H_
38
39 struct device;
40 struct notifier_block;
41
42 /*
43  * Regulator operating modes.
44  *
45  * Regulators can run in a variety of different operating modes depending on
46  * output load. This allows further system power savings by selecting the
47  * best (and most efficient) regulator mode for a desired load.
48  *
49  * Most drivers will only care about NORMAL. The modes below are generic and
50  * will probably not match the naming convention of your regulator data sheet
51  * but should match the use cases in the datasheet.
52  *
53  * In order of power efficiency (least efficient at top).
54  *
55  *  Mode       Description
56  *  FAST       Regulator can handle fast changes in it's load.
57  *             e.g. useful in CPU voltage & frequency scaling where
58  *             load can quickly increase with CPU frequency increases.
59  *
60  *  NORMAL     Normal regulator power supply mode. Most drivers will
61  *             use this mode.
62  *
63  *  IDLE       Regulator runs in a more efficient mode for light
64  *             loads. Can be used for devices that have a low power
65  *             requirement during periods of inactivity. This mode
66  *             may be more noisy than NORMAL and may not be able
67  *             to handle fast load switching.
68  *
69  *  STANDBY    Regulator runs in the most efficient mode for very
70  *             light loads. Can be used by devices when they are
71  *             in a sleep/standby state. This mode is likely to be
72  *             the most noisy and may not be able to handle fast load
73  *             switching.
74  *
75  * NOTE: Most regulators will only support a subset of these modes. Some
76  * will only just support NORMAL.
77  *
78  * These modes can be OR'ed together to make up a mask of valid register modes.
79  */
80
81 #define REGULATOR_MODE_FAST                     0x1
82 #define REGULATOR_MODE_NORMAL                   0x2
83 #define REGULATOR_MODE_IDLE                     0x4
84 #define REGULATOR_MODE_STANDBY                  0x8
85
86 /*
87  * Regulator notifier events.
88  *
89  * UNDER_VOLTAGE  Regulator output is under voltage.
90  * OVER_CURRENT   Regulator output current is too high.
91  * REGULATION_OUT Regulator output is out of regulation.
92  * FAIL           Regulator output has failed.
93  * OVER_TEMP      Regulator over temp.
94  * FORCE_DISABLE  Regulator forcibly shut down by software.
95  * VOLTAGE_CHANGE Regulator voltage changed.
96  * DISABLE        Regulator was disabled.
97  *
98  * NOTE: These events can be OR'ed together when passed into handler.
99  */
100
101 #define REGULATOR_EVENT_UNDER_VOLTAGE           0x01
102 #define REGULATOR_EVENT_OVER_CURRENT            0x02
103 #define REGULATOR_EVENT_REGULATION_OUT          0x04
104 #define REGULATOR_EVENT_FAIL                    0x08
105 #define REGULATOR_EVENT_OVER_TEMP               0x10
106 #define REGULATOR_EVENT_FORCE_DISABLE           0x20
107 #define REGULATOR_EVENT_VOLTAGE_CHANGE          0x40
108 #define REGULATOR_EVENT_DISABLE                 0x80
109 #define REGULATOR_EVENT_PRE_DISABLE             0x100
110 #define REGULATOR_EVENT_ENABLE                  0x200
111
112 struct regulator;
113
114 /**
115  * struct regulator_bulk_data - Data used for bulk regulator operations.
116  *
117  * @supply:   The name of the supply.  Initialised by the user before
118  *            using the bulk regulator APIs.
119  * @consumer: The regulator consumer for the supply.  This will be managed
120  *            by the bulk API.
121  *
122  * The regulator APIs provide a series of regulator_bulk_() API calls as
123  * a convenience to consumers which require multiple supplies.  This
124  * structure is used to manage data for these calls.
125  */
126 struct regulator_bulk_data {
127         const char *supply;
128         struct regulator *consumer;
129
130         /* private: Internal use */
131         int ret;
132 };
133
134 #if defined(CONFIG_REGULATOR)
135
136 /* regulator get and put */
137 struct regulator *__must_check regulator_get(struct device *dev,
138                                              const char *id);
139 struct regulator *__must_check devm_regulator_get(struct device *dev,
140                                              const char *id);
141 struct regulator *__must_check regulator_get_exclusive(struct device *dev,
142                                                        const char *id);
143 struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
144                                                         const char *id);
145 struct regulator *__must_check regulator_get_optional(struct device *dev,
146                                                       const char *id);
147 struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
148                                                            const char *id);
149 void regulator_put(struct regulator *regulator);
150 void devm_regulator_put(struct regulator *regulator);
151
152 int regulator_register_supply_alias(struct device *dev, const char *id,
153                                     struct device *alias_dev,
154                                     const char *alias_id);
155 void regulator_unregister_supply_alias(struct device *dev, const char *id);
156
157 int regulator_bulk_register_supply_alias(struct device *dev,
158                                          const char *const *id,
159                                          struct device *alias_dev,
160                                          const char *const *alias_id,
161                                          int num_id);
162 void regulator_bulk_unregister_supply_alias(struct device *dev,
163                                             const char * const *id, int num_id);
164
165 int devm_regulator_register_supply_alias(struct device *dev, const char *id,
166                                          struct device *alias_dev,
167                                          const char *alias_id);
168 void devm_regulator_unregister_supply_alias(struct device *dev,
169                                             const char *id);
170
171 int devm_regulator_bulk_register_supply_alias(struct device *dev,
172                                               const char *const *id,
173                                               struct device *alias_dev,
174                                               const char *const *alias_id,
175                                               int num_id);
176 void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
177                                                  const char *const *id,
178                                                  int num_id);
179
180 /* regulator output control and status */
181 int __must_check regulator_enable(struct regulator *regulator);
182 int regulator_disable(struct regulator *regulator);
183 int regulator_force_disable(struct regulator *regulator);
184 int regulator_is_enabled(struct regulator *regulator);
185 int regulator_disable_deferred(struct regulator *regulator, int ms);
186
187 int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
188                                     struct regulator_bulk_data *consumers);
189 int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
190                                          struct regulator_bulk_data *consumers);
191 int __must_check regulator_bulk_enable(int num_consumers,
192                                        struct regulator_bulk_data *consumers);
193 int regulator_bulk_disable(int num_consumers,
194                            struct regulator_bulk_data *consumers);
195 int regulator_bulk_force_disable(int num_consumers,
196                            struct regulator_bulk_data *consumers);
197 void regulator_bulk_free(int num_consumers,
198                          struct regulator_bulk_data *consumers);
199
200 int regulator_can_change_voltage(struct regulator *regulator);
201 int regulator_count_voltages(struct regulator *regulator);
202 int regulator_list_voltage(struct regulator *regulator, unsigned selector);
203 int regulator_is_supported_voltage(struct regulator *regulator,
204                                    int min_uV, int max_uV);
205 unsigned int regulator_get_linear_step(struct regulator *regulator);
206 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
207 int regulator_set_voltage_time(struct regulator *regulator,
208                                int old_uV, int new_uV);
209 int regulator_get_voltage(struct regulator *regulator);
210 int regulator_sync_voltage(struct regulator *regulator);
211 int regulator_set_current_limit(struct regulator *regulator,
212                                int min_uA, int max_uA);
213 int regulator_get_current_limit(struct regulator *regulator);
214
215 int regulator_set_mode(struct regulator *regulator, unsigned int mode);
216 unsigned int regulator_get_mode(struct regulator *regulator);
217 int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
218
219 int regulator_allow_bypass(struct regulator *regulator, bool allow);
220
221 /* regulator notifier block */
222 int regulator_register_notifier(struct regulator *regulator,
223                               struct notifier_block *nb);
224 int regulator_unregister_notifier(struct regulator *regulator,
225                                 struct notifier_block *nb);
226
227 /* driver data - core doesn't touch */
228 void *regulator_get_drvdata(struct regulator *regulator);
229 void regulator_set_drvdata(struct regulator *regulator, void *data);
230
231 #else
232
233 /*
234  * Make sure client drivers will still build on systems with no software
235  * controllable voltage or current regulators.
236  */
237 static inline struct regulator *__must_check regulator_get(struct device *dev,
238         const char *id)
239 {
240         /* Nothing except the stubbed out regulator API should be
241          * looking at the value except to check if it is an error
242          * value. Drivers are free to handle NULL specifically by
243          * skipping all regulator API calls, but they don't have to.
244          * Drivers which don't, should make sure they properly handle
245          * corner cases of the API, such as regulator_get_voltage()
246          * returning 0.
247          */
248         return NULL;
249 }
250
251 static inline struct regulator *__must_check
252 devm_regulator_get(struct device *dev, const char *id)
253 {
254         return NULL;
255 }
256
257 static inline struct regulator *__must_check
258 regulator_get_exclusive(struct device *dev, const char *id)
259 {
260         return NULL;
261 }
262
263 static inline struct regulator *__must_check
264 regulator_get_optional(struct device *dev, const char *id)
265 {
266         return ERR_PTR(-ENODEV);
267 }
268
269
270 static inline struct regulator *__must_check
271 devm_regulator_get_optional(struct device *dev, const char *id)
272 {
273         return ERR_PTR(-ENODEV);
274 }
275
276 static inline void regulator_put(struct regulator *regulator)
277 {
278 }
279
280 static inline void devm_regulator_put(struct regulator *regulator)
281 {
282 }
283
284 static inline int regulator_register_supply_alias(struct device *dev,
285                                                   const char *id,
286                                                   struct device *alias_dev,
287                                                   const char *alias_id)
288 {
289         return 0;
290 }
291
292 static inline void regulator_unregister_supply_alias(struct device *dev,
293                                                     const char *id)
294 {
295 }
296
297 static inline int regulator_bulk_register_supply_alias(struct device *dev,
298                                                 const char *const *id,
299                                                 struct device *alias_dev,
300                                                 const char * const *alias_id,
301                                                 int num_id)
302 {
303         return 0;
304 }
305
306 static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
307                                                 const char * const *id,
308                                                 int num_id)
309 {
310 }
311
312 static inline int devm_regulator_register_supply_alias(struct device *dev,
313                                                        const char *id,
314                                                        struct device *alias_dev,
315                                                        const char *alias_id)
316 {
317         return 0;
318 }
319
320 static inline void devm_regulator_unregister_supply_alias(struct device *dev,
321                                                           const char *id)
322 {
323 }
324
325 static inline int devm_regulator_bulk_register_supply_alias(struct device *dev,
326                                                 const char *const *id,
327                                                 struct device *alias_dev,
328                                                 const char *const *alias_id,
329                                                 int num_id)
330 {
331         return 0;
332 }
333
334 static inline void devm_regulator_bulk_unregister_supply_alias(
335         struct device *dev, const char *const *id, int num_id)
336 {
337 }
338
339 static inline int regulator_enable(struct regulator *regulator)
340 {
341         return 0;
342 }
343
344 static inline int regulator_disable(struct regulator *regulator)
345 {
346         return 0;
347 }
348
349 static inline int regulator_force_disable(struct regulator *regulator)
350 {
351         return 0;
352 }
353
354 static inline int regulator_disable_deferred(struct regulator *regulator,
355                                              int ms)
356 {
357         return 0;
358 }
359
360 static inline int regulator_is_enabled(struct regulator *regulator)
361 {
362         return 1;
363 }
364
365 static inline int regulator_bulk_get(struct device *dev,
366                                      int num_consumers,
367                                      struct regulator_bulk_data *consumers)
368 {
369         return 0;
370 }
371
372 static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
373                                           struct regulator_bulk_data *consumers)
374 {
375         return 0;
376 }
377
378 static inline int regulator_bulk_enable(int num_consumers,
379                                         struct regulator_bulk_data *consumers)
380 {
381         return 0;
382 }
383
384 static inline int regulator_bulk_disable(int num_consumers,
385                                          struct regulator_bulk_data *consumers)
386 {
387         return 0;
388 }
389
390 static inline int regulator_bulk_force_disable(int num_consumers,
391                                         struct regulator_bulk_data *consumers)
392 {
393         return 0;
394 }
395
396 static inline void regulator_bulk_free(int num_consumers,
397                                        struct regulator_bulk_data *consumers)
398 {
399 }
400
401 static inline int regulator_can_change_voltage(struct regulator *regulator)
402 {
403         return 0;
404 }
405
406 static inline int regulator_set_voltage(struct regulator *regulator,
407                                         int min_uV, int max_uV)
408 {
409         return 0;
410 }
411
412 static inline int regulator_set_voltage_time(struct regulator *regulator,
413                                              int old_uV, int new_uV)
414 {
415         return 0;
416 }
417
418 static inline int regulator_get_voltage(struct regulator *regulator)
419 {
420         return -EINVAL;
421 }
422
423 static inline int regulator_is_supported_voltage(struct regulator *regulator,
424                                    int min_uV, int max_uV)
425 {
426         return 0;
427 }
428
429 static inline int regulator_set_current_limit(struct regulator *regulator,
430                                              int min_uA, int max_uA)
431 {
432         return 0;
433 }
434
435 static inline int regulator_get_current_limit(struct regulator *regulator)
436 {
437         return 0;
438 }
439
440 static inline int regulator_set_mode(struct regulator *regulator,
441         unsigned int mode)
442 {
443         return 0;
444 }
445
446 static inline unsigned int regulator_get_mode(struct regulator *regulator)
447 {
448         return REGULATOR_MODE_NORMAL;
449 }
450
451 static inline int regulator_set_optimum_mode(struct regulator *regulator,
452                                         int load_uA)
453 {
454         return REGULATOR_MODE_NORMAL;
455 }
456
457 static inline int regulator_allow_bypass(struct regulator *regulator,
458                                          bool allow)
459 {
460         return 0;
461 }
462
463 static inline int regulator_register_notifier(struct regulator *regulator,
464                               struct notifier_block *nb)
465 {
466         return 0;
467 }
468
469 static inline int regulator_unregister_notifier(struct regulator *regulator,
470                                 struct notifier_block *nb)
471 {
472         return 0;
473 }
474
475 static inline void *regulator_get_drvdata(struct regulator *regulator)
476 {
477         return NULL;
478 }
479
480 static inline void regulator_set_drvdata(struct regulator *regulator,
481         void *data)
482 {
483 }
484
485 static inline int regulator_count_voltages(struct regulator *regulator)
486 {
487         return 0;
488 }
489 #endif
490
491 static inline int regulator_set_voltage_tol(struct regulator *regulator,
492                                             int new_uV, int tol_uV)
493 {
494         if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
495                 return 0;
496         else
497                 return regulator_set_voltage(regulator,
498                                              new_uV - tol_uV, new_uV + tol_uV);
499 }
500
501 static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
502                                                      int target_uV, int tol_uV)
503 {
504         return regulator_is_supported_voltage(regulator,
505                                               target_uV - tol_uV,
506                                               target_uV + tol_uV);
507 }
508
509 #endif