]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/regulator/consumer.h
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma
[mirror_ubuntu-bionic-kernel.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
5c9e7196 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
264b88c9 122#define REGULATOR_EVENT_ENABLE 0x1000
7179569a 123
1b5b4221
AH
124/*
125 * Regulator errors that can be queried using regulator_get_error_flags
126 *
127 * UNDER_VOLTAGE Regulator output is under voltage.
128 * OVER_CURRENT Regulator output current is too high.
129 * REGULATION_OUT Regulator output is out of regulation.
130 * FAIL Regulator output has failed.
131 * OVER_TEMP Regulator over temp.
132 *
133 * NOTE: These errors can be OR'ed together.
134 */
135
136#define REGULATOR_ERROR_UNDER_VOLTAGE BIT(1)
137#define REGULATOR_ERROR_OVER_CURRENT BIT(2)
138#define REGULATOR_ERROR_REGULATION_OUT BIT(3)
139#define REGULATOR_ERROR_FAIL BIT(4)
140#define REGULATOR_ERROR_OVER_TEMP BIT(5)
141
142
7179569a
HS
143/**
144 * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
145 *
146 * @old_uV: Current voltage before change.
147 * @min_uV: Min voltage we'll change to.
148 * @max_uV: Max voltage we'll change to.
149 */
150struct pre_voltage_change_data {
151 unsigned long old_uV;
152 unsigned long min_uV;
153 unsigned long max_uV;
154};
e2ce4eaa
LG
155
156struct regulator;
157
158/**
159 * struct regulator_bulk_data - Data used for bulk regulator operations.
160 *
69279fb9
MB
161 * @supply: The name of the supply. Initialised by the user before
162 * using the bulk regulator APIs.
163 * @consumer: The regulator consumer for the supply. This will be managed
164 * by the bulk API.
e2ce4eaa
LG
165 *
166 * The regulator APIs provide a series of regulator_bulk_() API calls as
167 * a convenience to consumers which require multiple supplies. This
168 * structure is used to manage data for these calls.
169 */
170struct regulator_bulk_data {
171 const char *supply;
172 struct regulator *consumer;
f21e0e81 173
bff747c5 174 /* private: Internal use */
f21e0e81 175 int ret;
e2ce4eaa
LG
176};
177
178#if defined(CONFIG_REGULATOR)
179
180/* regulator get and put */
181struct regulator *__must_check regulator_get(struct device *dev,
182 const char *id);
070b9079
SB
183struct regulator *__must_check devm_regulator_get(struct device *dev,
184 const char *id);
5ffbd136
MB
185struct regulator *__must_check regulator_get_exclusive(struct device *dev,
186 const char *id);
9efdd276
MK
187struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
188 const char *id);
de1dd9fd
MB
189struct regulator *__must_check regulator_get_optional(struct device *dev,
190 const char *id);
191struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
192 const char *id);
e2ce4eaa 193void regulator_put(struct regulator *regulator);
2950c4bb 194void devm_regulator_put(struct regulator *regulator);
e2ce4eaa 195
a06ccd9c
CK
196int regulator_register_supply_alias(struct device *dev, const char *id,
197 struct device *alias_dev,
198 const char *alias_id);
199void regulator_unregister_supply_alias(struct device *dev, const char *id);
200
9f8c0fe9
LJ
201int regulator_bulk_register_supply_alias(struct device *dev,
202 const char *const *id,
a06ccd9c 203 struct device *alias_dev,
9f8c0fe9
LJ
204 const char *const *alias_id,
205 int num_id);
a06ccd9c 206void regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9 207 const char * const *id, int num_id);
a06ccd9c
CK
208
209int devm_regulator_register_supply_alias(struct device *dev, const char *id,
210 struct device *alias_dev,
211 const char *alias_id);
212void devm_regulator_unregister_supply_alias(struct device *dev,
213 const char *id);
214
215int devm_regulator_bulk_register_supply_alias(struct device *dev,
9f8c0fe9 216 const char *const *id,
a06ccd9c 217 struct device *alias_dev,
9f8c0fe9 218 const char *const *alias_id,
a06ccd9c
CK
219 int num_id);
220void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9 221 const char *const *id,
a06ccd9c
CK
222 int num_id);
223
e2ce4eaa 224/* regulator output control and status */
c8801a8e 225int __must_check regulator_enable(struct regulator *regulator);
e2ce4eaa
LG
226int regulator_disable(struct regulator *regulator);
227int regulator_force_disable(struct regulator *regulator);
228int regulator_is_enabled(struct regulator *regulator);
da07ecd9 229int regulator_disable_deferred(struct regulator *regulator, int ms);
e2ce4eaa 230
c8801a8e
MB
231int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
232 struct regulator_bulk_data *consumers);
233int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
234 struct regulator_bulk_data *consumers);
235int __must_check regulator_bulk_enable(int num_consumers,
236 struct regulator_bulk_data *consumers);
e2ce4eaa
LG
237int regulator_bulk_disable(int num_consumers,
238 struct regulator_bulk_data *consumers);
e1de2f42
DK
239int regulator_bulk_force_disable(int num_consumers,
240 struct regulator_bulk_data *consumers);
e2ce4eaa
LG
241void regulator_bulk_free(int num_consumers,
242 struct regulator_bulk_data *consumers);
243
4367cfdc
DB
244int regulator_count_voltages(struct regulator *regulator);
245int regulator_list_voltage(struct regulator *regulator, unsigned selector);
a7a1ad90
MB
246int regulator_is_supported_voltage(struct regulator *regulator,
247 int min_uV, int max_uV);
2a668a8b 248unsigned int regulator_get_linear_step(struct regulator *regulator);
e2ce4eaa 249int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
88cd222b
LW
250int regulator_set_voltage_time(struct regulator *regulator,
251 int old_uV, int new_uV);
e2ce4eaa 252int regulator_get_voltage(struct regulator *regulator);
606a2562 253int regulator_sync_voltage(struct regulator *regulator);
e2ce4eaa
LG
254int regulator_set_current_limit(struct regulator *regulator,
255 int min_uA, int max_uA);
256int regulator_get_current_limit(struct regulator *regulator);
257
258int regulator_set_mode(struct regulator *regulator, unsigned int mode);
259unsigned int regulator_get_mode(struct regulator *regulator);
1b5b4221
AH
260int regulator_get_error_flags(struct regulator *regulator,
261 unsigned int *flags);
e39ce48f 262int regulator_set_load(struct regulator *regulator, int load_uA);
e2ce4eaa 263
f59c8f9f
MB
264int regulator_allow_bypass(struct regulator *regulator, bool allow);
265
04eca28c
TT
266struct regmap *regulator_get_regmap(struct regulator *regulator);
267int regulator_get_hardware_vsel_register(struct regulator *regulator,
268 unsigned *vsel_reg,
269 unsigned *vsel_mask);
270int regulator_list_hardware_vsel(struct regulator *regulator,
271 unsigned selector);
272
e2ce4eaa
LG
273/* regulator notifier block */
274int regulator_register_notifier(struct regulator *regulator,
275 struct notifier_block *nb);
046db763
CK
276int devm_regulator_register_notifier(struct regulator *regulator,
277 struct notifier_block *nb);
e2ce4eaa
LG
278int regulator_unregister_notifier(struct regulator *regulator,
279 struct notifier_block *nb);
046db763
CK
280void devm_regulator_unregister_notifier(struct regulator *regulator,
281 struct notifier_block *nb);
e2ce4eaa
LG
282
283/* driver data - core doesn't touch */
284void *regulator_get_drvdata(struct regulator *regulator);
285void regulator_set_drvdata(struct regulator *regulator, void *data);
286
287#else
288
289/*
290 * Make sure client drivers will still build on systems with no software
291 * controllable voltage or current regulators.
292 */
293static inline struct regulator *__must_check regulator_get(struct device *dev,
294 const char *id)
295{
296 /* Nothing except the stubbed out regulator API should be
297 * looking at the value except to check if it is an error
be1a50d4
JD
298 * value. Drivers are free to handle NULL specifically by
299 * skipping all regulator API calls, but they don't have to.
300 * Drivers which don't, should make sure they properly handle
301 * corner cases of the API, such as regulator_get_voltage()
302 * returning 0.
e2ce4eaa 303 */
be1a50d4 304 return NULL;
e2ce4eaa 305}
070b9079
SB
306
307static inline struct regulator *__must_check
308devm_regulator_get(struct device *dev, const char *id)
309{
310 return NULL;
311}
312
4bdfb272
MB
313static inline struct regulator *__must_check
314regulator_get_exclusive(struct device *dev, const char *id)
315{
70b946f9 316 return ERR_PTR(-ENODEV);
4bdfb272
MB
317}
318
de1dd9fd
MB
319static inline struct regulator *__must_check
320regulator_get_optional(struct device *dev, const char *id)
321{
df7926ff 322 return ERR_PTR(-ENODEV);
de1dd9fd
MB
323}
324
4bdfb272 325
070b9079 326static inline struct regulator *__must_check
de1dd9fd 327devm_regulator_get_optional(struct device *dev, const char *id)
070b9079 328{
df7926ff 329 return ERR_PTR(-ENODEV);
070b9079
SB
330}
331
e2ce4eaa
LG
332static inline void regulator_put(struct regulator *regulator)
333{
334}
335
2950c4bb
AL
336static inline void devm_regulator_put(struct regulator *regulator)
337{
338}
339
a06ccd9c
CK
340static inline int regulator_register_supply_alias(struct device *dev,
341 const char *id,
342 struct device *alias_dev,
343 const char *alias_id)
344{
345 return 0;
346}
347
348static inline void regulator_unregister_supply_alias(struct device *dev,
349 const char *id)
350{
351}
352
353static inline int regulator_bulk_register_supply_alias(struct device *dev,
9f8c0fe9
LJ
354 const char *const *id,
355 struct device *alias_dev,
356 const char * const *alias_id,
357 int num_id)
a06ccd9c
CK
358{
359 return 0;
360}
361
362static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
9f8c0fe9
LJ
363 const char * const *id,
364 int num_id)
a06ccd9c
CK
365{
366}
367
368static inline int devm_regulator_register_supply_alias(struct device *dev,
369 const char *id,
370 struct device *alias_dev,
371 const char *alias_id)
372{
373 return 0;
374}
375
376static inline void devm_regulator_unregister_supply_alias(struct device *dev,
377 const char *id)
378{
379}
380
9f8c0fe9
LJ
381static inline int devm_regulator_bulk_register_supply_alias(struct device *dev,
382 const char *const *id,
383 struct device *alias_dev,
384 const char *const *alias_id,
385 int num_id)
a06ccd9c
CK
386{
387 return 0;
388}
389
390static inline void devm_regulator_bulk_unregister_supply_alias(
9f8c0fe9 391 struct device *dev, const char *const *id, int num_id)
a06ccd9c
CK
392{
393}
394
e2ce4eaa
LG
395static inline int regulator_enable(struct regulator *regulator)
396{
397 return 0;
398}
399
400static inline int regulator_disable(struct regulator *regulator)
401{
402 return 0;
403}
404
935a5210
MH
405static inline int regulator_force_disable(struct regulator *regulator)
406{
407 return 0;
408}
409
da07ecd9
MB
410static inline int regulator_disable_deferred(struct regulator *regulator,
411 int ms)
412{
413 return 0;
414}
415
e2ce4eaa
LG
416static inline int regulator_is_enabled(struct regulator *regulator)
417{
418 return 1;
419}
420
421static inline int regulator_bulk_get(struct device *dev,
422 int num_consumers,
423 struct regulator_bulk_data *consumers)
424{
425 return 0;
426}
427
e24abd6e
AL
428static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
429 struct regulator_bulk_data *consumers)
430{
431 return 0;
432}
433
e2ce4eaa
LG
434static inline int regulator_bulk_enable(int num_consumers,
435 struct regulator_bulk_data *consumers)
436{
437 return 0;
438}
439
440static inline int regulator_bulk_disable(int num_consumers,
441 struct regulator_bulk_data *consumers)
442{
443 return 0;
444}
445
e1de2f42
DK
446static inline int regulator_bulk_force_disable(int num_consumers,
447 struct regulator_bulk_data *consumers)
448{
449 return 0;
450}
451
e2ce4eaa
LG
452static inline void regulator_bulk_free(int num_consumers,
453 struct regulator_bulk_data *consumers)
454{
455}
456
457static inline int regulator_set_voltage(struct regulator *regulator,
458 int min_uV, int max_uV)
459{
460 return 0;
461}
462
d660e92a
VK
463static inline int regulator_set_voltage_time(struct regulator *regulator,
464 int old_uV, int new_uV)
465{
466 return 0;
467}
468
e2ce4eaa
LG
469static inline int regulator_get_voltage(struct regulator *regulator)
470{
08aed2f6 471 return -EINVAL;
e2ce4eaa
LG
472}
473
4fe23791
PR
474static inline int regulator_is_supported_voltage(struct regulator *regulator,
475 int min_uV, int max_uV)
476{
477 return 0;
478}
479
e2ce4eaa
LG
480static inline int regulator_set_current_limit(struct regulator *regulator,
481 int min_uA, int max_uA)
482{
483 return 0;
484}
485
486static inline int regulator_get_current_limit(struct regulator *regulator)
487{
488 return 0;
489}
490
491static inline int regulator_set_mode(struct regulator *regulator,
492 unsigned int mode)
493{
494 return 0;
495}
496
497static inline unsigned int regulator_get_mode(struct regulator *regulator)
498{
499 return REGULATOR_MODE_NORMAL;
500}
501
30103b5b
DL
502static inline int regulator_get_error_flags(struct regulator *regulator,
503 unsigned int *flags)
1b5b4221
AH
504{
505 return -EINVAL;
506}
507
e39ce48f 508static inline int regulator_set_load(struct regulator *regulator, int load_uA)
e2ce4eaa
LG
509{
510 return REGULATOR_MODE_NORMAL;
511}
512
f59c8f9f
MB
513static inline int regulator_allow_bypass(struct regulator *regulator,
514 bool allow)
515{
516 return 0;
517}
518
3bc0312e 519static inline struct regmap *regulator_get_regmap(struct regulator *regulator)
04eca28c
TT
520{
521 return ERR_PTR(-EOPNOTSUPP);
522}
523
3bc0312e
MB
524static inline int regulator_get_hardware_vsel_register(struct regulator *regulator,
525 unsigned *vsel_reg,
526 unsigned *vsel_mask)
04eca28c
TT
527{
528 return -EOPNOTSUPP;
529}
530
3bc0312e
MB
531static inline int regulator_list_hardware_vsel(struct regulator *regulator,
532 unsigned selector)
04eca28c
TT
533{
534 return -EOPNOTSUPP;
535}
536
e2ce4eaa
LG
537static inline int regulator_register_notifier(struct regulator *regulator,
538 struct notifier_block *nb)
539{
540 return 0;
541}
542
046db763
CK
543static inline int devm_regulator_register_notifier(struct regulator *regulator,
544 struct notifier_block *nb)
545{
546 return 0;
547}
548
e2ce4eaa
LG
549static inline int regulator_unregister_notifier(struct regulator *regulator,
550 struct notifier_block *nb)
551{
552 return 0;
553}
554
046db763
CK
555static inline int devm_regulator_unregister_notifier(struct regulator *regulator,
556 struct notifier_block *nb)
557{
558 return 0;
559}
560
e2ce4eaa
LG
561static inline void *regulator_get_drvdata(struct regulator *regulator)
562{
563 return NULL;
564}
565
566static inline void regulator_set_drvdata(struct regulator *regulator,
567 void *data)
568{
569}
570
1a8f85d4
PR
571static inline int regulator_count_voltages(struct regulator *regulator)
572{
573 return 0;
574}
5127e31a
SP
575
576static inline int regulator_list_voltage(struct regulator *regulator, unsigned selector)
577{
578 return -EINVAL;
579}
580
e2ce4eaa
LG
581#endif
582
30f93ca8
VK
583static inline int regulator_set_voltage_triplet(struct regulator *regulator,
584 int min_uV, int target_uV,
585 int max_uV)
586{
587 if (regulator_set_voltage(regulator, target_uV, max_uV) == 0)
588 return 0;
589
590 return regulator_set_voltage(regulator, min_uV, max_uV);
591}
592
3f196577
SG
593static inline int regulator_set_voltage_tol(struct regulator *regulator,
594 int new_uV, int tol_uV)
595{
dc9ceed6
MB
596 if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
597 return 0;
598 else
599 return regulator_set_voltage(regulator,
600 new_uV - tol_uV, new_uV + tol_uV);
3f196577
SG
601}
602
fe1e43f7
MB
603static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
604 int target_uV, int tol_uV)
605{
606 return regulator_is_supported_voltage(regulator,
607 target_uV - tol_uV,
608 target_uV + tol_uV);
609}
610
e2ce4eaa 611#endif