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.
16 * o Voltage and current level control.
17 * o Operating mode control.
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>
41 struct notifier_block
;
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).
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
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
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
124 * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
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.
130 struct pre_voltage_change_data
{
131 unsigned long old_uV
;
132 unsigned long min_uV
;
133 unsigned long max_uV
;
139 * struct regulator_bulk_data - Data used for bulk regulator operations.
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
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.
150 struct regulator_bulk_data
{
152 struct regulator
*consumer
;
154 /* private: Internal use */
158 #if defined(CONFIG_REGULATOR)
160 /* regulator get and put */
161 struct regulator
*__must_check
regulator_get(struct device
*dev
,
163 struct regulator
*__must_check
devm_regulator_get(struct device
*dev
,
165 struct regulator
*__must_check
regulator_get_exclusive(struct device
*dev
,
167 struct regulator
*__must_check
devm_regulator_get_exclusive(struct device
*dev
,
169 struct regulator
*__must_check
regulator_get_optional(struct device
*dev
,
171 struct regulator
*__must_check
devm_regulator_get_optional(struct device
*dev
,
173 void regulator_put(struct regulator
*regulator
);
174 void devm_regulator_put(struct regulator
*regulator
);
176 int regulator_register_supply_alias(struct device
*dev
, const char *id
,
177 struct device
*alias_dev
,
178 const char *alias_id
);
179 void regulator_unregister_supply_alias(struct device
*dev
, const char *id
);
181 int regulator_bulk_register_supply_alias(struct device
*dev
,
182 const char *const *id
,
183 struct device
*alias_dev
,
184 const char *const *alias_id
,
186 void regulator_bulk_unregister_supply_alias(struct device
*dev
,
187 const char * const *id
, int num_id
);
189 int devm_regulator_register_supply_alias(struct device
*dev
, const char *id
,
190 struct device
*alias_dev
,
191 const char *alias_id
);
192 void devm_regulator_unregister_supply_alias(struct device
*dev
,
195 int devm_regulator_bulk_register_supply_alias(struct device
*dev
,
196 const char *const *id
,
197 struct device
*alias_dev
,
198 const char *const *alias_id
,
200 void devm_regulator_bulk_unregister_supply_alias(struct device
*dev
,
201 const char *const *id
,
204 /* regulator output control and status */
205 int __must_check
regulator_enable(struct regulator
*regulator
);
206 int regulator_disable(struct regulator
*regulator
);
207 int regulator_force_disable(struct regulator
*regulator
);
208 int regulator_is_enabled(struct regulator
*regulator
);
209 int regulator_disable_deferred(struct regulator
*regulator
, int ms
);
211 int __must_check
regulator_bulk_get(struct device
*dev
, int num_consumers
,
212 struct regulator_bulk_data
*consumers
);
213 int __must_check
devm_regulator_bulk_get(struct device
*dev
, int num_consumers
,
214 struct regulator_bulk_data
*consumers
);
215 int __must_check
regulator_bulk_enable(int num_consumers
,
216 struct regulator_bulk_data
*consumers
);
217 int regulator_bulk_disable(int num_consumers
,
218 struct regulator_bulk_data
*consumers
);
219 int regulator_bulk_force_disable(int num_consumers
,
220 struct regulator_bulk_data
*consumers
);
221 void regulator_bulk_free(int num_consumers
,
222 struct regulator_bulk_data
*consumers
);
224 int regulator_count_voltages(struct regulator
*regulator
);
225 int regulator_list_voltage(struct regulator
*regulator
, unsigned selector
);
226 int regulator_is_supported_voltage(struct regulator
*regulator
,
227 int min_uV
, int max_uV
);
228 unsigned int regulator_get_linear_step(struct regulator
*regulator
);
229 int regulator_set_voltage(struct regulator
*regulator
, int min_uV
, int max_uV
);
230 int regulator_set_voltage_time(struct regulator
*regulator
,
231 int old_uV
, int new_uV
);
232 int regulator_get_voltage(struct regulator
*regulator
);
233 int regulator_sync_voltage(struct regulator
*regulator
);
234 int regulator_set_current_limit(struct regulator
*regulator
,
235 int min_uA
, int max_uA
);
236 int regulator_get_current_limit(struct regulator
*regulator
);
238 int regulator_set_mode(struct regulator
*regulator
, unsigned int mode
);
239 unsigned int regulator_get_mode(struct regulator
*regulator
);
240 int regulator_set_load(struct regulator
*regulator
, int load_uA
);
242 int regulator_allow_bypass(struct regulator
*regulator
, bool allow
);
244 struct regmap
*regulator_get_regmap(struct regulator
*regulator
);
245 int regulator_get_hardware_vsel_register(struct regulator
*regulator
,
247 unsigned *vsel_mask
);
248 int regulator_list_hardware_vsel(struct regulator
*regulator
,
251 /* regulator notifier block */
252 int regulator_register_notifier(struct regulator
*regulator
,
253 struct notifier_block
*nb
);
254 int devm_regulator_register_notifier(struct regulator
*regulator
,
255 struct notifier_block
*nb
);
256 int regulator_unregister_notifier(struct regulator
*regulator
,
257 struct notifier_block
*nb
);
258 void devm_regulator_unregister_notifier(struct regulator
*regulator
,
259 struct notifier_block
*nb
);
261 /* driver data - core doesn't touch */
262 void *regulator_get_drvdata(struct regulator
*regulator
);
263 void regulator_set_drvdata(struct regulator
*regulator
, void *data
);
268 * Make sure client drivers will still build on systems with no software
269 * controllable voltage or current regulators.
271 static inline struct regulator
*__must_check
regulator_get(struct device
*dev
,
274 /* Nothing except the stubbed out regulator API should be
275 * looking at the value except to check if it is an error
276 * value. Drivers are free to handle NULL specifically by
277 * skipping all regulator API calls, but they don't have to.
278 * Drivers which don't, should make sure they properly handle
279 * corner cases of the API, such as regulator_get_voltage()
285 static inline struct regulator
*__must_check
286 devm_regulator_get(struct device
*dev
, const char *id
)
291 static inline struct regulator
*__must_check
292 regulator_get_exclusive(struct device
*dev
, const char *id
)
294 return ERR_PTR(-ENODEV
);
297 static inline struct regulator
*__must_check
298 regulator_get_optional(struct device
*dev
, const char *id
)
300 return ERR_PTR(-ENODEV
);
304 static inline struct regulator
*__must_check
305 devm_regulator_get_optional(struct device
*dev
, const char *id
)
307 return ERR_PTR(-ENODEV
);
310 static inline void regulator_put(struct regulator
*regulator
)
314 static inline void devm_regulator_put(struct regulator
*regulator
)
318 static inline int regulator_register_supply_alias(struct device
*dev
,
320 struct device
*alias_dev
,
321 const char *alias_id
)
326 static inline void regulator_unregister_supply_alias(struct device
*dev
,
331 static inline int regulator_bulk_register_supply_alias(struct device
*dev
,
332 const char *const *id
,
333 struct device
*alias_dev
,
334 const char * const *alias_id
,
340 static inline void regulator_bulk_unregister_supply_alias(struct device
*dev
,
341 const char * const *id
,
346 static inline int devm_regulator_register_supply_alias(struct device
*dev
,
348 struct device
*alias_dev
,
349 const char *alias_id
)
354 static inline void devm_regulator_unregister_supply_alias(struct device
*dev
,
359 static inline int devm_regulator_bulk_register_supply_alias(struct device
*dev
,
360 const char *const *id
,
361 struct device
*alias_dev
,
362 const char *const *alias_id
,
368 static inline void devm_regulator_bulk_unregister_supply_alias(
369 struct device
*dev
, const char *const *id
, int num_id
)
373 static inline int regulator_enable(struct regulator
*regulator
)
378 static inline int regulator_disable(struct regulator
*regulator
)
383 static inline int regulator_force_disable(struct regulator
*regulator
)
388 static inline int regulator_disable_deferred(struct regulator
*regulator
,
394 static inline int regulator_is_enabled(struct regulator
*regulator
)
399 static inline int regulator_bulk_get(struct device
*dev
,
401 struct regulator_bulk_data
*consumers
)
406 static inline int devm_regulator_bulk_get(struct device
*dev
, int num_consumers
,
407 struct regulator_bulk_data
*consumers
)
412 static inline int regulator_bulk_enable(int num_consumers
,
413 struct regulator_bulk_data
*consumers
)
418 static inline int regulator_bulk_disable(int num_consumers
,
419 struct regulator_bulk_data
*consumers
)
424 static inline int regulator_bulk_force_disable(int num_consumers
,
425 struct regulator_bulk_data
*consumers
)
430 static inline void regulator_bulk_free(int num_consumers
,
431 struct regulator_bulk_data
*consumers
)
435 static inline int regulator_set_voltage(struct regulator
*regulator
,
436 int min_uV
, int max_uV
)
441 static inline int regulator_set_voltage_time(struct regulator
*regulator
,
442 int old_uV
, int new_uV
)
447 static inline int regulator_get_voltage(struct regulator
*regulator
)
452 static inline int regulator_is_supported_voltage(struct regulator
*regulator
,
453 int min_uV
, int max_uV
)
458 static inline int regulator_set_current_limit(struct regulator
*regulator
,
459 int min_uA
, int max_uA
)
464 static inline int regulator_get_current_limit(struct regulator
*regulator
)
469 static inline int regulator_set_mode(struct regulator
*regulator
,
475 static inline unsigned int regulator_get_mode(struct regulator
*regulator
)
477 return REGULATOR_MODE_NORMAL
;
480 static inline int regulator_set_load(struct regulator
*regulator
, int load_uA
)
482 return REGULATOR_MODE_NORMAL
;
485 static inline int regulator_allow_bypass(struct regulator
*regulator
,
491 static inline struct regmap
*regulator_get_regmap(struct regulator
*regulator
)
493 return ERR_PTR(-EOPNOTSUPP
);
496 static inline int regulator_get_hardware_vsel_register(struct regulator
*regulator
,
503 static inline int regulator_list_hardware_vsel(struct regulator
*regulator
,
509 static inline int regulator_register_notifier(struct regulator
*regulator
,
510 struct notifier_block
*nb
)
515 static inline int devm_regulator_register_notifier(struct regulator
*regulator
,
516 struct notifier_block
*nb
)
521 static inline int regulator_unregister_notifier(struct regulator
*regulator
,
522 struct notifier_block
*nb
)
527 static inline int devm_regulator_unregister_notifier(struct regulator
*regulator
,
528 struct notifier_block
*nb
)
533 static inline void *regulator_get_drvdata(struct regulator
*regulator
)
538 static inline void regulator_set_drvdata(struct regulator
*regulator
,
543 static inline int regulator_count_voltages(struct regulator
*regulator
)
548 static inline int regulator_list_voltage(struct regulator
*regulator
, unsigned selector
)
555 static inline int regulator_set_voltage_triplet(struct regulator
*regulator
,
556 int min_uV
, int target_uV
,
559 if (regulator_set_voltage(regulator
, target_uV
, max_uV
) == 0)
562 return regulator_set_voltage(regulator
, min_uV
, max_uV
);
565 static inline int regulator_set_voltage_tol(struct regulator
*regulator
,
566 int new_uV
, int tol_uV
)
568 if (regulator_set_voltage(regulator
, new_uV
, new_uV
+ tol_uV
) == 0)
571 return regulator_set_voltage(regulator
,
572 new_uV
- tol_uV
, new_uV
+ tol_uV
);
575 static inline int regulator_is_supported_voltage_tol(struct regulator
*regulator
,
576 int target_uV
, int tol_uV
)
578 return regulator_is_supported_voltage(regulator
,
This page took 0.0433 seconds and 5 git commands to generate.