Merge tag 'usb-4.0-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
[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
174e964e
GR
38#include <linux/err.h>
39
313162d0
PG
40struct device;
41struct notifier_block;
04eca28c 42struct regmap;
b56daf13 43
e2ce4eaa
LG
44/*
45 * Regulator operating modes.
46 *
47 * Regulators can run in a variety of different operating modes depending on
48 * output load. This allows further system power savings by selecting the
49 * best (and most efficient) regulator mode for a desired load.
50 *
51 * Most drivers will only care about NORMAL. The modes below are generic and
52 * will probably not match the naming convention of your regulator data sheet
53 * but should match the use cases in the datasheet.
54 *
55 * In order of power efficiency (least efficient at top).
56 *
57 * Mode Description
58 * FAST Regulator can handle fast changes in it's load.
59 * e.g. useful in CPU voltage & frequency scaling where
60 * load can quickly increase with CPU frequency increases.
61 *
62 * NORMAL Normal regulator power supply mode. Most drivers will
63 * use this mode.
64 *
65 * IDLE Regulator runs in a more efficient mode for light
66 * loads. Can be used for devices that have a low power
67 * requirement during periods of inactivity. This mode
68 * may be more noisy than NORMAL and may not be able
69 * to handle fast load switching.
70 *
71 * STANDBY Regulator runs in the most efficient mode for very
72 * light loads. Can be used by devices when they are
73 * in a sleep/standby state. This mode is likely to be
74 * the most noisy and may not be able to handle fast load
75 * switching.
76 *
77 * NOTE: Most regulators will only support a subset of these modes. Some
78 * will only just support NORMAL.
79 *
80 * These modes can be OR'ed together to make up a mask of valid register modes.
81 */
82
83#define REGULATOR_MODE_FAST 0x1
84#define REGULATOR_MODE_NORMAL 0x2
85#define REGULATOR_MODE_IDLE 0x4
86#define REGULATOR_MODE_STANDBY 0x8
87
88/*
89 * Regulator notifier events.
90 *
91 * UNDER_VOLTAGE Regulator output is under voltage.
92 * OVER_CURRENT Regulator output current is too high.
93 * REGULATION_OUT Regulator output is out of regulation.
94 * FAIL Regulator output has failed.
95 * OVER_TEMP Regulator over temp.
84b68263 96 * FORCE_DISABLE Regulator forcibly shut down by software.
b136fb44 97 * VOLTAGE_CHANGE Regulator voltage changed.
7179569a 98 * Data passed is old voltage cast to (void *).
84b68263 99 * DISABLE Regulator was disabled.
7179569a
HS
100 * PRE_VOLTAGE_CHANGE Regulator is about to have voltage changed.
101 * Data passed is "struct pre_voltage_change_data"
102 * ABORT_VOLTAGE_CHANGE Regulator voltage change failed for some reason.
103 * Data passed is old voltage cast to (void *).
a1c8a551
RF
104 * PRE_DISABLE Regulator is about to be disabled
105 * ABORT_DISABLE Regulator disable failed for some reason
e2ce4eaa
LG
106 *
107 * NOTE: These events can be OR'ed together when passed into handler.
108 */
109
110#define REGULATOR_EVENT_UNDER_VOLTAGE 0x01
111#define REGULATOR_EVENT_OVER_CURRENT 0x02
112#define REGULATOR_EVENT_REGULATION_OUT 0x04
113#define REGULATOR_EVENT_FAIL 0x08
114#define REGULATOR_EVENT_OVER_TEMP 0x10
115#define REGULATOR_EVENT_FORCE_DISABLE 0x20
b136fb44 116#define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40
84b68263 117#define REGULATOR_EVENT_DISABLE 0x80
7179569a
HS
118#define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100
119#define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200
a1c8a551
RF
120#define REGULATOR_EVENT_PRE_DISABLE 0x400
121#define REGULATOR_EVENT_ABORT_DISABLE 0x800
7179569a
HS
122
123/**
124 * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
125 *
126 * @old_uV: Current voltage before change.
127 * @min_uV: Min voltage we'll change to.
128 * @max_uV: Max voltage we'll change to.
129 */
130struct pre_voltage_change_data {
131 unsigned long old_uV;
132 unsigned long min_uV;
133 unsigned long max_uV;
134};
e2ce4eaa
LG
135
136struct regulator;
137
138/**
139 * struct regulator_bulk_data - Data used for bulk regulator operations.
140 *
69279fb9
MB
141 * @supply: The name of the supply. Initialised by the user before
142 * using the bulk regulator APIs.
143 * @consumer: The regulator consumer for the supply. This will be managed
144 * by the bulk API.
e2ce4eaa
LG
145 *
146 * The regulator APIs provide a series of regulator_bulk_() API calls as
147 * a convenience to consumers which require multiple supplies. This
148 * structure is used to manage data for these calls.
149 */
150struct regulator_bulk_data {
151 const char *supply;
152 struct regulator *consumer;
f21e0e81 153
bff747c5 154 /* private: Internal use */
f21e0e81 155 int ret;
e2ce4eaa
LG
156};
157
158#if defined(CONFIG_REGULATOR)
159
160/* regulator get and put */
161struct regulator *__must_check regulator_get(struct device *dev,
162 const char *id);
070b9079
SB
163struct regulator *__must_check devm_regulator_get(struct device *dev,
164 const char *id);
5ffbd136
MB
165struct regulator *__must_check regulator_get_exclusive(struct device *dev,
166 const char *id);
9efdd276
MK
167struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
168 const char *id);
de1dd9fd
MB
169struct regulator *__must_check regulator_get_optional(struct device *dev,
170 const char *id);
171struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
172 const char *id);
e2ce4eaa 173void regulator_put(struct regulator *regulator);
2950c4bb 174void devm_regulator_put(struct regulator *regulator);
e2ce4eaa 175
a06ccd9c
CK
176int regulator_register_supply_alias(struct device *dev, const char *id,
177 struct device *alias_dev,
178 const char *alias_id);
179void regulator_unregister_supply_alias(struct device *dev, const char *id);
180
9f8c0fe9
LJ
181int regulator_bulk_register_supply_alias(struct device *dev,
182 const char *const *id,
a06ccd9c 183 struct device *alias_dev,
9f8c0fe9
LJ
184 const char *const *alias_id,
185 int num_id);
a06ccd9c 186void regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9 187 const char * const *id, int num_id);
a06ccd9c
CK
188
189int devm_regulator_register_supply_alias(struct device *dev, const char *id,
190 struct device *alias_dev,
191 const char *alias_id);
192void devm_regulator_unregister_supply_alias(struct device *dev,
193 const char *id);
194
195int devm_regulator_bulk_register_supply_alias(struct device *dev,
9f8c0fe9 196 const char *const *id,
a06ccd9c 197 struct device *alias_dev,
9f8c0fe9 198 const char *const *alias_id,
a06ccd9c
CK
199 int num_id);
200void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9 201 const char *const *id,
a06ccd9c
CK
202 int num_id);
203
e2ce4eaa 204/* regulator output control and status */
c8801a8e 205int __must_check regulator_enable(struct regulator *regulator);
e2ce4eaa
LG
206int regulator_disable(struct regulator *regulator);
207int regulator_force_disable(struct regulator *regulator);
208int regulator_is_enabled(struct regulator *regulator);
da07ecd9 209int regulator_disable_deferred(struct regulator *regulator, int ms);
e2ce4eaa 210
c8801a8e
MB
211int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
212 struct regulator_bulk_data *consumers);
213int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
214 struct regulator_bulk_data *consumers);
215int __must_check regulator_bulk_enable(int num_consumers,
216 struct regulator_bulk_data *consumers);
e2ce4eaa
LG
217int regulator_bulk_disable(int num_consumers,
218 struct regulator_bulk_data *consumers);
e1de2f42
DK
219int regulator_bulk_force_disable(int num_consumers,
220 struct regulator_bulk_data *consumers);
e2ce4eaa
LG
221void regulator_bulk_free(int num_consumers,
222 struct regulator_bulk_data *consumers);
223
d1e7de30 224int regulator_can_change_voltage(struct regulator *regulator);
4367cfdc
DB
225int regulator_count_voltages(struct regulator *regulator);
226int regulator_list_voltage(struct regulator *regulator, unsigned selector);
a7a1ad90
MB
227int regulator_is_supported_voltage(struct regulator *regulator,
228 int min_uV, int max_uV);
2a668a8b 229unsigned int regulator_get_linear_step(struct regulator *regulator);
e2ce4eaa 230int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
88cd222b
LW
231int regulator_set_voltage_time(struct regulator *regulator,
232 int old_uV, int new_uV);
e2ce4eaa 233int regulator_get_voltage(struct regulator *regulator);
606a2562 234int regulator_sync_voltage(struct regulator *regulator);
e2ce4eaa
LG
235int regulator_set_current_limit(struct regulator *regulator,
236 int min_uA, int max_uA);
237int regulator_get_current_limit(struct regulator *regulator);
238
239int regulator_set_mode(struct regulator *regulator, unsigned int mode);
240unsigned int regulator_get_mode(struct regulator *regulator);
241int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
242
f59c8f9f
MB
243int regulator_allow_bypass(struct regulator *regulator, bool allow);
244
04eca28c
TT
245struct regmap *regulator_get_regmap(struct regulator *regulator);
246int regulator_get_hardware_vsel_register(struct regulator *regulator,
247 unsigned *vsel_reg,
248 unsigned *vsel_mask);
249int regulator_list_hardware_vsel(struct regulator *regulator,
250 unsigned selector);
251
e2ce4eaa
LG
252/* regulator notifier block */
253int regulator_register_notifier(struct regulator *regulator,
254 struct notifier_block *nb);
255int regulator_unregister_notifier(struct regulator *regulator,
256 struct notifier_block *nb);
257
258/* driver data - core doesn't touch */
259void *regulator_get_drvdata(struct regulator *regulator);
260void regulator_set_drvdata(struct regulator *regulator, void *data);
261
262#else
263
264/*
265 * Make sure client drivers will still build on systems with no software
266 * controllable voltage or current regulators.
267 */
268static inline struct regulator *__must_check regulator_get(struct device *dev,
269 const char *id)
270{
271 /* Nothing except the stubbed out regulator API should be
272 * looking at the value except to check if it is an error
be1a50d4
JD
273 * value. Drivers are free to handle NULL specifically by
274 * skipping all regulator API calls, but they don't have to.
275 * Drivers which don't, should make sure they properly handle
276 * corner cases of the API, such as regulator_get_voltage()
277 * returning 0.
e2ce4eaa 278 */
be1a50d4 279 return NULL;
e2ce4eaa 280}
070b9079
SB
281
282static inline struct regulator *__must_check
283devm_regulator_get(struct device *dev, const char *id)
284{
285 return NULL;
286}
287
4bdfb272
MB
288static inline struct regulator *__must_check
289regulator_get_exclusive(struct device *dev, const char *id)
290{
70b946f9 291 return ERR_PTR(-ENODEV);
4bdfb272
MB
292}
293
de1dd9fd
MB
294static inline struct regulator *__must_check
295regulator_get_optional(struct device *dev, const char *id)
296{
df7926ff 297 return ERR_PTR(-ENODEV);
de1dd9fd
MB
298}
299
4bdfb272 300
070b9079 301static inline struct regulator *__must_check
de1dd9fd 302devm_regulator_get_optional(struct device *dev, const char *id)
070b9079 303{
df7926ff 304 return ERR_PTR(-ENODEV);
070b9079
SB
305}
306
e2ce4eaa
LG
307static inline void regulator_put(struct regulator *regulator)
308{
309}
310
2950c4bb
AL
311static inline void devm_regulator_put(struct regulator *regulator)
312{
313}
314
a06ccd9c
CK
315static inline int regulator_register_supply_alias(struct device *dev,
316 const char *id,
317 struct device *alias_dev,
318 const char *alias_id)
319{
320 return 0;
321}
322
323static inline void regulator_unregister_supply_alias(struct device *dev,
324 const char *id)
325{
326}
327
328static inline int regulator_bulk_register_supply_alias(struct device *dev,
9f8c0fe9
LJ
329 const char *const *id,
330 struct device *alias_dev,
331 const char * const *alias_id,
332 int num_id)
a06ccd9c
CK
333{
334 return 0;
335}
336
337static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9
LJ
338 const char * const *id,
339 int num_id)
a06ccd9c
CK
340{
341}
342
343static inline int devm_regulator_register_supply_alias(struct device *dev,
344 const char *id,
345 struct device *alias_dev,
346 const char *alias_id)
347{
348 return 0;
349}
350
351static inline void devm_regulator_unregister_supply_alias(struct device *dev,
352 const char *id)
353{
354}
355
9f8c0fe9
LJ
356static inline int devm_regulator_bulk_register_supply_alias(struct device *dev,
357 const char *const *id,
358 struct device *alias_dev,
359 const char *const *alias_id,
360 int num_id)
a06ccd9c
CK
361{
362 return 0;
363}
364
365static inline void devm_regulator_bulk_unregister_supply_alias(
9f8c0fe9 366 struct device *dev, const char *const *id, int num_id)
a06ccd9c
CK
367{
368}
369
e2ce4eaa
LG
370static inline int regulator_enable(struct regulator *regulator)
371{
372 return 0;
373}
374
375static inline int regulator_disable(struct regulator *regulator)
376{
377 return 0;
378}
379
935a5210
MH
380static inline int regulator_force_disable(struct regulator *regulator)
381{
382 return 0;
383}
384
da07ecd9
MB
385static inline int regulator_disable_deferred(struct regulator *regulator,
386 int ms)
387{
388 return 0;
389}
390
e2ce4eaa
LG
391static inline int regulator_is_enabled(struct regulator *regulator)
392{
393 return 1;
394}
395
396static inline int regulator_bulk_get(struct device *dev,
397 int num_consumers,
398 struct regulator_bulk_data *consumers)
399{
400 return 0;
401}
402
e24abd6e
AL
403static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
404 struct regulator_bulk_data *consumers)
405{
406 return 0;
407}
408
e2ce4eaa
LG
409static inline int regulator_bulk_enable(int num_consumers,
410 struct regulator_bulk_data *consumers)
411{
412 return 0;
413}
414
415static inline int regulator_bulk_disable(int num_consumers,
416 struct regulator_bulk_data *consumers)
417{
418 return 0;
419}
420
e1de2f42
DK
421static inline int regulator_bulk_force_disable(int num_consumers,
422 struct regulator_bulk_data *consumers)
423{
424 return 0;
425}
426
e2ce4eaa
LG
427static inline void regulator_bulk_free(int num_consumers,
428 struct regulator_bulk_data *consumers)
429{
430}
431
b14903e1
AB
432static inline int regulator_can_change_voltage(struct regulator *regulator)
433{
434 return 0;
435}
e2ce4eaa
LG
436
437static inline int regulator_set_voltage(struct regulator *regulator,
438 int min_uV, int max_uV)
439{
440 return 0;
441}
442
d660e92a
VK
443static inline int regulator_set_voltage_time(struct regulator *regulator,
444 int old_uV, int new_uV)
445{
446 return 0;
447}
448
e2ce4eaa
LG
449static inline int regulator_get_voltage(struct regulator *regulator)
450{
08aed2f6 451 return -EINVAL;
e2ce4eaa
LG
452}
453
4fe23791
PR
454static inline int regulator_is_supported_voltage(struct regulator *regulator,
455 int min_uV, int max_uV)
456{
457 return 0;
458}
459
e2ce4eaa
LG
460static inline int regulator_set_current_limit(struct regulator *regulator,
461 int min_uA, int max_uA)
462{
463 return 0;
464}
465
466static inline int regulator_get_current_limit(struct regulator *regulator)
467{
468 return 0;
469}
470
471static inline int regulator_set_mode(struct regulator *regulator,
472 unsigned int mode)
473{
474 return 0;
475}
476
477static inline unsigned int regulator_get_mode(struct regulator *regulator)
478{
479 return REGULATOR_MODE_NORMAL;
480}
481
482static inline int regulator_set_optimum_mode(struct regulator *regulator,
483 int load_uA)
484{
485 return REGULATOR_MODE_NORMAL;
486}
487
f59c8f9f
MB
488static inline int regulator_allow_bypass(struct regulator *regulator,
489 bool allow)
490{
491 return 0;
492}
493
3bc0312e 494static inline struct regmap *regulator_get_regmap(struct regulator *regulator)
04eca28c
TT
495{
496 return ERR_PTR(-EOPNOTSUPP);
497}
498
3bc0312e
MB
499static inline int regulator_get_hardware_vsel_register(struct regulator *regulator,
500 unsigned *vsel_reg,
501 unsigned *vsel_mask)
04eca28c
TT
502{
503 return -EOPNOTSUPP;
504}
505
3bc0312e
MB
506static inline int regulator_list_hardware_vsel(struct regulator *regulator,
507 unsigned selector)
04eca28c
TT
508{
509 return -EOPNOTSUPP;
510}
511
e2ce4eaa
LG
512static inline int regulator_register_notifier(struct regulator *regulator,
513 struct notifier_block *nb)
514{
515 return 0;
516}
517
518static inline int regulator_unregister_notifier(struct regulator *regulator,
519 struct notifier_block *nb)
520{
521 return 0;
522}
523
524static inline void *regulator_get_drvdata(struct regulator *regulator)
525{
526 return NULL;
527}
528
529static inline void regulator_set_drvdata(struct regulator *regulator,
530 void *data)
531{
532}
533
1a8f85d4
PR
534static inline int regulator_count_voltages(struct regulator *regulator)
535{
536 return 0;
537}
e2ce4eaa
LG
538#endif
539
3f196577
SG
540static inline int regulator_set_voltage_tol(struct regulator *regulator,
541 int new_uV, int tol_uV)
542{
dc9ceed6
MB
543 if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
544 return 0;
545 else
546 return regulator_set_voltage(regulator,
547 new_uV - tol_uV, new_uV + tol_uV);
3f196577
SG
548}
549
fe1e43f7
MB
550static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
551 int target_uV, int tol_uV)
552{
553 return regulator_is_supported_voltage(regulator,
554 target_uV - tol_uV,
555 target_uV + tol_uV);
556}
557
e2ce4eaa 558#endif
This page took 0.838934 seconds and 5 git commands to generate.