Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / include / linux / regulator / consumer.h
blobdf176d7c2b87c00356a11b383a61185e7f3e47ae
1 /*
2 * consumer.h -- SoC Regulator consumer support.
4 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
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.
12 * Regulator Consumer Interface.
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
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.
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.
35 #ifndef __LINUX_REGULATOR_CONSUMER_H_
36 #define __LINUX_REGULATOR_CONSUMER_H_
38 #include <linux/err.h>
40 struct device;
41 struct notifier_block;
42 struct regmap;
45 * Regulator operating modes.
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.
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.
55 * In order of power efficiency (least efficient at top).
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.
62 * NORMAL Normal regulator power supply mode. Most drivers will
63 * use this mode.
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.
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.
77 * NOTE: Most regulators will only support a subset of these modes. Some
78 * will only just support NORMAL.
80 * These modes can be OR'ed together to make up a mask of valid register modes.
83 #define REGULATOR_MODE_FAST 0x1
84 #define REGULATOR_MODE_NORMAL 0x2
85 #define REGULATOR_MODE_IDLE 0x4
86 #define REGULATOR_MODE_STANDBY 0x8
89 * Regulator notifier events.
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.
96 * FORCE_DISABLE Regulator forcibly shut down by software.
97 * VOLTAGE_CHANGE Regulator voltage changed.
98 * Data passed is old voltage cast to (void *).
99 * DISABLE Regulator was disabled.
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 *).
104 * PRE_DISABLE Regulator is about to be disabled
105 * ABORT_DISABLE Regulator disable failed for some reason
107 * NOTE: These events can be OR'ed together when passed into handler.
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
116 #define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40
117 #define REGULATOR_EVENT_DISABLE 0x80
118 #define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100
119 #define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200
120 #define REGULATOR_EVENT_PRE_DISABLE 0x400
121 #define REGULATOR_EVENT_ABORT_DISABLE 0x800
122 #define REGULATOR_EVENT_ENABLE 0x1000
125 * Regulator errors that can be queried using regulator_get_error_flags
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.
133 * NOTE: These errors can be OR'ed together.
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)
144 * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
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.
150 struct pre_voltage_change_data {
151 unsigned long old_uV;
152 unsigned long min_uV;
153 unsigned long max_uV;
156 struct regulator;
159 * struct regulator_bulk_data - Data used for bulk regulator operations.
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.
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.
170 struct regulator_bulk_data {
171 const char *supply;
172 struct regulator *consumer;
174 /* private: Internal use */
175 int ret;
178 #if defined(CONFIG_REGULATOR)
180 /* regulator get and put */
181 struct regulator *__must_check regulator_get(struct device *dev,
182 const char *id);
183 struct regulator *__must_check devm_regulator_get(struct device *dev,
184 const char *id);
185 struct regulator *__must_check regulator_get_exclusive(struct device *dev,
186 const char *id);
187 struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
188 const char *id);
189 struct regulator *__must_check regulator_get_optional(struct device *dev,
190 const char *id);
191 struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
192 const char *id);
193 void regulator_put(struct regulator *regulator);
194 void devm_regulator_put(struct regulator *regulator);
196 int regulator_register_supply_alias(struct device *dev, const char *id,
197 struct device *alias_dev,
198 const char *alias_id);
199 void regulator_unregister_supply_alias(struct device *dev, const char *id);
201 int regulator_bulk_register_supply_alias(struct device *dev,
202 const char *const *id,
203 struct device *alias_dev,
204 const char *const *alias_id,
205 int num_id);
206 void regulator_bulk_unregister_supply_alias(struct device *dev,
207 const char * const *id, int num_id);
209 int devm_regulator_register_supply_alias(struct device *dev, const char *id,
210 struct device *alias_dev,
211 const char *alias_id);
212 void devm_regulator_unregister_supply_alias(struct device *dev,
213 const char *id);
215 int devm_regulator_bulk_register_supply_alias(struct device *dev,
216 const char *const *id,
217 struct device *alias_dev,
218 const char *const *alias_id,
219 int num_id);
220 void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
221 const char *const *id,
222 int num_id);
224 /* regulator output control and status */
225 int __must_check regulator_enable(struct regulator *regulator);
226 int regulator_disable(struct regulator *regulator);
227 int regulator_force_disable(struct regulator *regulator);
228 int regulator_is_enabled(struct regulator *regulator);
229 int regulator_disable_deferred(struct regulator *regulator, int ms);
231 int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
232 struct regulator_bulk_data *consumers);
233 int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
234 struct regulator_bulk_data *consumers);
235 int __must_check regulator_bulk_enable(int num_consumers,
236 struct regulator_bulk_data *consumers);
237 int regulator_bulk_disable(int num_consumers,
238 struct regulator_bulk_data *consumers);
239 int regulator_bulk_force_disable(int num_consumers,
240 struct regulator_bulk_data *consumers);
241 void regulator_bulk_free(int num_consumers,
242 struct regulator_bulk_data *consumers);
244 int regulator_count_voltages(struct regulator *regulator);
245 int regulator_list_voltage(struct regulator *regulator, unsigned selector);
246 int regulator_is_supported_voltage(struct regulator *regulator,
247 int min_uV, int max_uV);
248 unsigned int regulator_get_linear_step(struct regulator *regulator);
249 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
250 int regulator_set_voltage_time(struct regulator *regulator,
251 int old_uV, int new_uV);
252 int regulator_get_voltage(struct regulator *regulator);
253 int regulator_sync_voltage(struct regulator *regulator);
254 int regulator_set_current_limit(struct regulator *regulator,
255 int min_uA, int max_uA);
256 int regulator_get_current_limit(struct regulator *regulator);
258 int regulator_set_mode(struct regulator *regulator, unsigned int mode);
259 unsigned int regulator_get_mode(struct regulator *regulator);
260 int regulator_get_error_flags(struct regulator *regulator,
261 unsigned int *flags);
262 int regulator_set_load(struct regulator *regulator, int load_uA);
264 int regulator_allow_bypass(struct regulator *regulator, bool allow);
266 struct regmap *regulator_get_regmap(struct regulator *regulator);
267 int regulator_get_hardware_vsel_register(struct regulator *regulator,
268 unsigned *vsel_reg,
269 unsigned *vsel_mask);
270 int regulator_list_hardware_vsel(struct regulator *regulator,
271 unsigned selector);
273 /* regulator notifier block */
274 int regulator_register_notifier(struct regulator *regulator,
275 struct notifier_block *nb);
276 int devm_regulator_register_notifier(struct regulator *regulator,
277 struct notifier_block *nb);
278 int regulator_unregister_notifier(struct regulator *regulator,
279 struct notifier_block *nb);
280 void devm_regulator_unregister_notifier(struct regulator *regulator,
281 struct notifier_block *nb);
283 /* driver data - core doesn't touch */
284 void *regulator_get_drvdata(struct regulator *regulator);
285 void regulator_set_drvdata(struct regulator *regulator, void *data);
287 #else
290 * Make sure client drivers will still build on systems with no software
291 * controllable voltage or current regulators.
293 static inline struct regulator *__must_check regulator_get(struct device *dev,
294 const char *id)
296 /* Nothing except the stubbed out regulator API should be
297 * looking at the value except to check if it is an error
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.
304 return NULL;
307 static inline struct regulator *__must_check
308 devm_regulator_get(struct device *dev, const char *id)
310 return NULL;
313 static inline struct regulator *__must_check
314 regulator_get_exclusive(struct device *dev, const char *id)
316 return ERR_PTR(-ENODEV);
319 static inline struct regulator *__must_check
320 regulator_get_optional(struct device *dev, const char *id)
322 return ERR_PTR(-ENODEV);
326 static inline struct regulator *__must_check
327 devm_regulator_get_optional(struct device *dev, const char *id)
329 return ERR_PTR(-ENODEV);
332 static inline void regulator_put(struct regulator *regulator)
336 static inline void devm_regulator_put(struct regulator *regulator)
340 static inline int regulator_register_supply_alias(struct device *dev,
341 const char *id,
342 struct device *alias_dev,
343 const char *alias_id)
345 return 0;
348 static inline void regulator_unregister_supply_alias(struct device *dev,
349 const char *id)
353 static inline int regulator_bulk_register_supply_alias(struct device *dev,
354 const char *const *id,
355 struct device *alias_dev,
356 const char * const *alias_id,
357 int num_id)
359 return 0;
362 static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
363 const char * const *id,
364 int num_id)
368 static inline int devm_regulator_register_supply_alias(struct device *dev,
369 const char *id,
370 struct device *alias_dev,
371 const char *alias_id)
373 return 0;
376 static inline void devm_regulator_unregister_supply_alias(struct device *dev,
377 const char *id)
381 static 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)
387 return 0;
390 static inline void devm_regulator_bulk_unregister_supply_alias(
391 struct device *dev, const char *const *id, int num_id)
395 static inline int regulator_enable(struct regulator *regulator)
397 return 0;
400 static inline int regulator_disable(struct regulator *regulator)
402 return 0;
405 static inline int regulator_force_disable(struct regulator *regulator)
407 return 0;
410 static inline int regulator_disable_deferred(struct regulator *regulator,
411 int ms)
413 return 0;
416 static inline int regulator_is_enabled(struct regulator *regulator)
418 return 1;
421 static inline int regulator_bulk_get(struct device *dev,
422 int num_consumers,
423 struct regulator_bulk_data *consumers)
425 return 0;
428 static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
429 struct regulator_bulk_data *consumers)
431 return 0;
434 static inline int regulator_bulk_enable(int num_consumers,
435 struct regulator_bulk_data *consumers)
437 return 0;
440 static inline int regulator_bulk_disable(int num_consumers,
441 struct regulator_bulk_data *consumers)
443 return 0;
446 static inline int regulator_bulk_force_disable(int num_consumers,
447 struct regulator_bulk_data *consumers)
449 return 0;
452 static inline void regulator_bulk_free(int num_consumers,
453 struct regulator_bulk_data *consumers)
457 static inline int regulator_set_voltage(struct regulator *regulator,
458 int min_uV, int max_uV)
460 return 0;
463 static inline int regulator_set_voltage_time(struct regulator *regulator,
464 int old_uV, int new_uV)
466 return 0;
469 static inline int regulator_get_voltage(struct regulator *regulator)
471 return -EINVAL;
474 static inline int regulator_is_supported_voltage(struct regulator *regulator,
475 int min_uV, int max_uV)
477 return 0;
480 static inline int regulator_set_current_limit(struct regulator *regulator,
481 int min_uA, int max_uA)
483 return 0;
486 static inline int regulator_get_current_limit(struct regulator *regulator)
488 return 0;
491 static inline int regulator_set_mode(struct regulator *regulator,
492 unsigned int mode)
494 return 0;
497 static inline unsigned int regulator_get_mode(struct regulator *regulator)
499 return REGULATOR_MODE_NORMAL;
502 static inline int regulator_get_error_flags(struct regulator *regulator,
503 unsigned int *flags)
505 return -EINVAL;
508 static inline int regulator_set_load(struct regulator *regulator, int load_uA)
510 return REGULATOR_MODE_NORMAL;
513 static inline int regulator_allow_bypass(struct regulator *regulator,
514 bool allow)
516 return 0;
519 static inline struct regmap *regulator_get_regmap(struct regulator *regulator)
521 return ERR_PTR(-EOPNOTSUPP);
524 static inline int regulator_get_hardware_vsel_register(struct regulator *regulator,
525 unsigned *vsel_reg,
526 unsigned *vsel_mask)
528 return -EOPNOTSUPP;
531 static inline int regulator_list_hardware_vsel(struct regulator *regulator,
532 unsigned selector)
534 return -EOPNOTSUPP;
537 static inline int regulator_register_notifier(struct regulator *regulator,
538 struct notifier_block *nb)
540 return 0;
543 static inline int devm_regulator_register_notifier(struct regulator *regulator,
544 struct notifier_block *nb)
546 return 0;
549 static inline int regulator_unregister_notifier(struct regulator *regulator,
550 struct notifier_block *nb)
552 return 0;
555 static inline int devm_regulator_unregister_notifier(struct regulator *regulator,
556 struct notifier_block *nb)
558 return 0;
561 static inline void *regulator_get_drvdata(struct regulator *regulator)
563 return NULL;
566 static inline void regulator_set_drvdata(struct regulator *regulator,
567 void *data)
571 static inline int regulator_count_voltages(struct regulator *regulator)
573 return 0;
576 static inline int regulator_list_voltage(struct regulator *regulator, unsigned selector)
578 return -EINVAL;
581 #endif
583 static inline int regulator_set_voltage_triplet(struct regulator *regulator,
584 int min_uV, int target_uV,
585 int max_uV)
587 if (regulator_set_voltage(regulator, target_uV, max_uV) == 0)
588 return 0;
590 return regulator_set_voltage(regulator, min_uV, max_uV);
593 static inline int regulator_set_voltage_tol(struct regulator *regulator,
594 int new_uV, int tol_uV)
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);
603 static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
604 int target_uV, int tol_uV)
606 return regulator_is_supported_voltage(regulator,
607 target_uV - tol_uV,
608 target_uV + tol_uV);
611 #endif