Linux 3.17-rc1
[deliverable/linux.git] / include / linux / regulator / consumer.h
CommitLineData
e2ce4eaa
LG
1/*
2 * consumer.h -- SoC Regulator consumer support.
3 *
4 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
5 *
1dd68f01 6 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
e2ce4eaa
LG
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Regulator Consumer Interface.
13 *
14 * A Power Management Regulator framework for SoC based devices.
15 * Features:-
16 * o Voltage and current level control.
17 * o Operating mode control.
18 * o Regulator status.
19 * o sysfs entries for showing client devices and status
20 *
21 * EXPERIMENTAL FEATURES:
22 * Dynamic Regulator operating Mode Switching (DRMS) - allows regulators
23 * to use most efficient operating mode depending upon voltage and load and
24 * is transparent to client drivers.
25 *
26 * e.g. Devices x,y,z share regulator r. Device x and y draw 20mA each during
27 * IO and 1mA at idle. Device z draws 100mA when under load and 5mA when
28 * idling. Regulator r has > 90% efficiency in NORMAL mode at loads > 100mA
29 * but this drops rapidly to 60% when below 100mA. Regulator r has > 90%
30 * efficiency in IDLE mode at loads < 10mA. Thus regulator r will operate
31 * in normal mode for loads > 10mA and in IDLE mode for load <= 10mA.
32 *
33 */
34
35#ifndef __LINUX_REGULATOR_CONSUMER_H_
36#define __LINUX_REGULATOR_CONSUMER_H_
37
313162d0
PG
38struct device;
39struct notifier_block;
04eca28c 40struct regmap;
b56daf13 41
e2ce4eaa
LG
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.
84b68263 94 * FORCE_DISABLE Regulator forcibly shut down by software.
b136fb44 95 * VOLTAGE_CHANGE Regulator voltage changed.
84b68263 96 * DISABLE Regulator was disabled.
e2ce4eaa
LG
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
b136fb44 107#define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40
84b68263 108#define REGULATOR_EVENT_DISABLE 0x80
e2ce4eaa
LG
109
110struct regulator;
111
112/**
113 * struct regulator_bulk_data - Data used for bulk regulator operations.
114 *
69279fb9
MB
115 * @supply: The name of the supply. Initialised by the user before
116 * using the bulk regulator APIs.
117 * @consumer: The regulator consumer for the supply. This will be managed
118 * by the bulk API.
e2ce4eaa
LG
119 *
120 * The regulator APIs provide a series of regulator_bulk_() API calls as
121 * a convenience to consumers which require multiple supplies. This
122 * structure is used to manage data for these calls.
123 */
124struct regulator_bulk_data {
125 const char *supply;
126 struct regulator *consumer;
f21e0e81 127
bff747c5 128 /* private: Internal use */
f21e0e81 129 int ret;
e2ce4eaa
LG
130};
131
132#if defined(CONFIG_REGULATOR)
133
134/* regulator get and put */
135struct regulator *__must_check regulator_get(struct device *dev,
136 const char *id);
070b9079
SB
137struct regulator *__must_check devm_regulator_get(struct device *dev,
138 const char *id);
5ffbd136
MB
139struct regulator *__must_check regulator_get_exclusive(struct device *dev,
140 const char *id);
9efdd276
MK
141struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
142 const char *id);
de1dd9fd
MB
143struct regulator *__must_check regulator_get_optional(struct device *dev,
144 const char *id);
145struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
146 const char *id);
e2ce4eaa 147void regulator_put(struct regulator *regulator);
2950c4bb 148void devm_regulator_put(struct regulator *regulator);
e2ce4eaa 149
a06ccd9c
CK
150int regulator_register_supply_alias(struct device *dev, const char *id,
151 struct device *alias_dev,
152 const char *alias_id);
153void regulator_unregister_supply_alias(struct device *dev, const char *id);
154
9f8c0fe9
LJ
155int regulator_bulk_register_supply_alias(struct device *dev,
156 const char *const *id,
a06ccd9c 157 struct device *alias_dev,
9f8c0fe9
LJ
158 const char *const *alias_id,
159 int num_id);
a06ccd9c 160void regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9 161 const char * const *id, int num_id);
a06ccd9c
CK
162
163int devm_regulator_register_supply_alias(struct device *dev, const char *id,
164 struct device *alias_dev,
165 const char *alias_id);
166void devm_regulator_unregister_supply_alias(struct device *dev,
167 const char *id);
168
169int devm_regulator_bulk_register_supply_alias(struct device *dev,
9f8c0fe9 170 const char *const *id,
a06ccd9c 171 struct device *alias_dev,
9f8c0fe9 172 const char *const *alias_id,
a06ccd9c
CK
173 int num_id);
174void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9 175 const char *const *id,
a06ccd9c
CK
176 int num_id);
177
e2ce4eaa 178/* regulator output control and status */
c8801a8e 179int __must_check regulator_enable(struct regulator *regulator);
e2ce4eaa
LG
180int regulator_disable(struct regulator *regulator);
181int regulator_force_disable(struct regulator *regulator);
182int regulator_is_enabled(struct regulator *regulator);
da07ecd9 183int regulator_disable_deferred(struct regulator *regulator, int ms);
e2ce4eaa 184
c8801a8e
MB
185int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
186 struct regulator_bulk_data *consumers);
187int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
188 struct regulator_bulk_data *consumers);
189int __must_check regulator_bulk_enable(int num_consumers,
190 struct regulator_bulk_data *consumers);
e2ce4eaa
LG
191int regulator_bulk_disable(int num_consumers,
192 struct regulator_bulk_data *consumers);
e1de2f42
DK
193int regulator_bulk_force_disable(int num_consumers,
194 struct regulator_bulk_data *consumers);
e2ce4eaa
LG
195void regulator_bulk_free(int num_consumers,
196 struct regulator_bulk_data *consumers);
197
d1e7de30 198int regulator_can_change_voltage(struct regulator *regulator);
4367cfdc
DB
199int regulator_count_voltages(struct regulator *regulator);
200int regulator_list_voltage(struct regulator *regulator, unsigned selector);
a7a1ad90
MB
201int regulator_is_supported_voltage(struct regulator *regulator,
202 int min_uV, int max_uV);
2a668a8b 203unsigned int regulator_get_linear_step(struct regulator *regulator);
e2ce4eaa 204int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
88cd222b
LW
205int regulator_set_voltage_time(struct regulator *regulator,
206 int old_uV, int new_uV);
e2ce4eaa 207int regulator_get_voltage(struct regulator *regulator);
606a2562 208int regulator_sync_voltage(struct regulator *regulator);
e2ce4eaa
LG
209int regulator_set_current_limit(struct regulator *regulator,
210 int min_uA, int max_uA);
211int regulator_get_current_limit(struct regulator *regulator);
212
213int regulator_set_mode(struct regulator *regulator, unsigned int mode);
214unsigned int regulator_get_mode(struct regulator *regulator);
215int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
216
f59c8f9f
MB
217int regulator_allow_bypass(struct regulator *regulator, bool allow);
218
04eca28c
TT
219struct regmap *regulator_get_regmap(struct regulator *regulator);
220int regulator_get_hardware_vsel_register(struct regulator *regulator,
221 unsigned *vsel_reg,
222 unsigned *vsel_mask);
223int regulator_list_hardware_vsel(struct regulator *regulator,
224 unsigned selector);
225
e2ce4eaa
LG
226/* regulator notifier block */
227int regulator_register_notifier(struct regulator *regulator,
228 struct notifier_block *nb);
229int regulator_unregister_notifier(struct regulator *regulator,
230 struct notifier_block *nb);
231
232/* driver data - core doesn't touch */
233void *regulator_get_drvdata(struct regulator *regulator);
234void regulator_set_drvdata(struct regulator *regulator, void *data);
235
236#else
237
238/*
239 * Make sure client drivers will still build on systems with no software
240 * controllable voltage or current regulators.
241 */
242static inline struct regulator *__must_check regulator_get(struct device *dev,
243 const char *id)
244{
245 /* Nothing except the stubbed out regulator API should be
246 * looking at the value except to check if it is an error
be1a50d4
JD
247 * value. Drivers are free to handle NULL specifically by
248 * skipping all regulator API calls, but they don't have to.
249 * Drivers which don't, should make sure they properly handle
250 * corner cases of the API, such as regulator_get_voltage()
251 * returning 0.
e2ce4eaa 252 */
be1a50d4 253 return NULL;
e2ce4eaa 254}
070b9079
SB
255
256static inline struct regulator *__must_check
257devm_regulator_get(struct device *dev, const char *id)
258{
259 return NULL;
260}
261
4bdfb272
MB
262static inline struct regulator *__must_check
263regulator_get_exclusive(struct device *dev, const char *id)
264{
265 return NULL;
266}
267
de1dd9fd
MB
268static inline struct regulator *__must_check
269regulator_get_optional(struct device *dev, const char *id)
270{
df7926ff 271 return ERR_PTR(-ENODEV);
de1dd9fd
MB
272}
273
4bdfb272 274
070b9079 275static inline struct regulator *__must_check
de1dd9fd 276devm_regulator_get_optional(struct device *dev, const char *id)
070b9079 277{
df7926ff 278 return ERR_PTR(-ENODEV);
070b9079
SB
279}
280
e2ce4eaa
LG
281static inline void regulator_put(struct regulator *regulator)
282{
283}
284
2950c4bb
AL
285static inline void devm_regulator_put(struct regulator *regulator)
286{
287}
288
a06ccd9c
CK
289static inline int regulator_register_supply_alias(struct device *dev,
290 const char *id,
291 struct device *alias_dev,
292 const char *alias_id)
293{
294 return 0;
295}
296
297static inline void regulator_unregister_supply_alias(struct device *dev,
298 const char *id)
299{
300}
301
302static inline int regulator_bulk_register_supply_alias(struct device *dev,
9f8c0fe9
LJ
303 const char *const *id,
304 struct device *alias_dev,
305 const char * const *alias_id,
306 int num_id)
a06ccd9c
CK
307{
308 return 0;
309}
310
311static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9
LJ
312 const char * const *id,
313 int num_id)
a06ccd9c
CK
314{
315}
316
317static inline int devm_regulator_register_supply_alias(struct device *dev,
318 const char *id,
319 struct device *alias_dev,
320 const char *alias_id)
321{
322 return 0;
323}
324
325static inline void devm_regulator_unregister_supply_alias(struct device *dev,
326 const char *id)
327{
328}
329
9f8c0fe9
LJ
330static inline int devm_regulator_bulk_register_supply_alias(struct device *dev,
331 const char *const *id,
332 struct device *alias_dev,
333 const char *const *alias_id,
334 int num_id)
a06ccd9c
CK
335{
336 return 0;
337}
338
339static inline void devm_regulator_bulk_unregister_supply_alias(
9f8c0fe9 340 struct device *dev, const char *const *id, int num_id)
a06ccd9c
CK
341{
342}
343
e2ce4eaa
LG
344static inline int regulator_enable(struct regulator *regulator)
345{
346 return 0;
347}
348
349static inline int regulator_disable(struct regulator *regulator)
350{
351 return 0;
352}
353
935a5210
MH
354static inline int regulator_force_disable(struct regulator *regulator)
355{
356 return 0;
357}
358
da07ecd9
MB
359static inline int regulator_disable_deferred(struct regulator *regulator,
360 int ms)
361{
362 return 0;
363}
364
e2ce4eaa
LG
365static inline int regulator_is_enabled(struct regulator *regulator)
366{
367 return 1;
368}
369
370static inline int regulator_bulk_get(struct device *dev,
371 int num_consumers,
372 struct regulator_bulk_data *consumers)
373{
374 return 0;
375}
376
e24abd6e
AL
377static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
378 struct regulator_bulk_data *consumers)
379{
380 return 0;
381}
382
e2ce4eaa
LG
383static inline int regulator_bulk_enable(int num_consumers,
384 struct regulator_bulk_data *consumers)
385{
386 return 0;
387}
388
389static inline int regulator_bulk_disable(int num_consumers,
390 struct regulator_bulk_data *consumers)
391{
392 return 0;
393}
394
e1de2f42
DK
395static inline int regulator_bulk_force_disable(int num_consumers,
396 struct regulator_bulk_data *consumers)
397{
398 return 0;
399}
400
e2ce4eaa
LG
401static inline void regulator_bulk_free(int num_consumers,
402 struct regulator_bulk_data *consumers)
403{
404}
405
b14903e1
AB
406static inline int regulator_can_change_voltage(struct regulator *regulator)
407{
408 return 0;
409}
e2ce4eaa
LG
410
411static inline int regulator_set_voltage(struct regulator *regulator,
412 int min_uV, int max_uV)
413{
414 return 0;
415}
416
d660e92a
VK
417static inline int regulator_set_voltage_time(struct regulator *regulator,
418 int old_uV, int new_uV)
419{
420 return 0;
421}
422
e2ce4eaa
LG
423static inline int regulator_get_voltage(struct regulator *regulator)
424{
08aed2f6 425 return -EINVAL;
e2ce4eaa
LG
426}
427
4fe23791
PR
428static inline int regulator_is_supported_voltage(struct regulator *regulator,
429 int min_uV, int max_uV)
430{
431 return 0;
432}
433
e2ce4eaa
LG
434static inline int regulator_set_current_limit(struct regulator *regulator,
435 int min_uA, int max_uA)
436{
437 return 0;
438}
439
440static inline int regulator_get_current_limit(struct regulator *regulator)
441{
442 return 0;
443}
444
445static inline int regulator_set_mode(struct regulator *regulator,
446 unsigned int mode)
447{
448 return 0;
449}
450
451static inline unsigned int regulator_get_mode(struct regulator *regulator)
452{
453 return REGULATOR_MODE_NORMAL;
454}
455
456static inline int regulator_set_optimum_mode(struct regulator *regulator,
457 int load_uA)
458{
459 return REGULATOR_MODE_NORMAL;
460}
461
f59c8f9f
MB
462static inline int regulator_allow_bypass(struct regulator *regulator,
463 bool allow)
464{
465 return 0;
466}
467
3bc0312e 468static inline struct regmap *regulator_get_regmap(struct regulator *regulator)
04eca28c
TT
469{
470 return ERR_PTR(-EOPNOTSUPP);
471}
472
3bc0312e
MB
473static inline int regulator_get_hardware_vsel_register(struct regulator *regulator,
474 unsigned *vsel_reg,
475 unsigned *vsel_mask)
04eca28c
TT
476{
477 return -EOPNOTSUPP;
478}
479
3bc0312e
MB
480static inline int regulator_list_hardware_vsel(struct regulator *regulator,
481 unsigned selector)
04eca28c
TT
482{
483 return -EOPNOTSUPP;
484}
485
e2ce4eaa
LG
486static inline int regulator_register_notifier(struct regulator *regulator,
487 struct notifier_block *nb)
488{
489 return 0;
490}
491
492static inline int regulator_unregister_notifier(struct regulator *regulator,
493 struct notifier_block *nb)
494{
495 return 0;
496}
497
498static inline void *regulator_get_drvdata(struct regulator *regulator)
499{
500 return NULL;
501}
502
503static inline void regulator_set_drvdata(struct regulator *regulator,
504 void *data)
505{
506}
507
1a8f85d4
PR
508static inline int regulator_count_voltages(struct regulator *regulator)
509{
510 return 0;
511}
e2ce4eaa
LG
512#endif
513
3f196577
SG
514static inline int regulator_set_voltage_tol(struct regulator *regulator,
515 int new_uV, int tol_uV)
516{
dc9ceed6
MB
517 if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
518 return 0;
519 else
520 return regulator_set_voltage(regulator,
521 new_uV - tol_uV, new_uV + tol_uV);
3f196577
SG
522}
523
fe1e43f7
MB
524static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
525 int target_uV, int tol_uV)
526{
527 return regulator_is_supported_voltage(regulator,
528 target_uV - tol_uV,
529 target_uV + tol_uV);
530}
531
e2ce4eaa 532#endif
This page took 0.637673 seconds and 5 git commands to generate.