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_
39 struct notifier_block;
43 * Regulator operating modes.
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.
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.
53 * In order of power efficiency (least efficient at top).
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.
60 * NORMAL Normal regulator power supply mode. Most drivers will
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.
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
75 * NOTE: Most regulators will only support a subset of these modes. Some
76 * will only just support NORMAL.
78 * These modes can be OR'ed together to make up a mask of valid register modes.
81 #define REGULATOR_MODE_FAST 0x1
82 #define REGULATOR_MODE_NORMAL 0x2
83 #define REGULATOR_MODE_IDLE 0x4
84 #define REGULATOR_MODE_STANDBY 0x8
87 * Regulator notifier events.
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.
94 * FORCE_DISABLE Regulator forcibly shut down by software.
95 * VOLTAGE_CHANGE Regulator voltage changed.
96 * Data passed is old voltage cast to (void *).
97 * DISABLE Regulator was disabled.
98 * PRE_VOLTAGE_CHANGE Regulator is about to have voltage changed.
99 * Data passed is "struct pre_voltage_change_data"
100 * ABORT_VOLTAGE_CHANGE Regulator voltage change failed for some reason.
101 * Data passed is old voltage cast to (void *).
103 * NOTE: These events can be OR'ed together when passed into handler.
106 #define REGULATOR_EVENT_UNDER_VOLTAGE 0x01
107 #define REGULATOR_EVENT_OVER_CURRENT 0x02
108 #define REGULATOR_EVENT_REGULATION_OUT 0x04
109 #define REGULATOR_EVENT_FAIL 0x08
110 #define REGULATOR_EVENT_OVER_TEMP 0x10
111 #define REGULATOR_EVENT_FORCE_DISABLE 0x20
112 #define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40
113 #define REGULATOR_EVENT_DISABLE 0x80
114 #define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100
115 #define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200
118 * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
120 * @old_uV: Current voltage before change.
121 * @min_uV: Min voltage we'll change to.
122 * @max_uV: Max voltage we'll change to.
124 struct pre_voltage_change_data {
125 unsigned long old_uV;
126 unsigned long min_uV;
127 unsigned long max_uV;
133 * struct regulator_bulk_data - Data used for bulk regulator operations.
135 * @supply: The name of the supply. Initialised by the user before
136 * using the bulk regulator APIs.
137 * @consumer: The regulator consumer for the supply. This will be managed
140 * The regulator APIs provide a series of regulator_bulk_() API calls as
141 * a convenience to consumers which require multiple supplies. This
142 * structure is used to manage data for these calls.
144 struct regulator_bulk_data {
146 struct regulator *consumer;
148 /* private: Internal use */
152 #if defined(CONFIG_REGULATOR)
154 /* regulator get and put */
155 struct regulator *__must_check regulator_get(struct device *dev,
157 struct regulator *__must_check devm_regulator_get(struct device *dev,
159 struct regulator *__must_check regulator_get_exclusive(struct device *dev,
161 struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
163 struct regulator *__must_check regulator_get_optional(struct device *dev,
165 struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
167 void regulator_put(struct regulator *regulator);
168 void devm_regulator_put(struct regulator *regulator);
170 int regulator_register_supply_alias(struct device *dev, const char *id,
171 struct device *alias_dev,
172 const char *alias_id);
173 void regulator_unregister_supply_alias(struct device *dev, const char *id);
175 int regulator_bulk_register_supply_alias(struct device *dev,
176 const char *const *id,
177 struct device *alias_dev,
178 const char *const *alias_id,
180 void regulator_bulk_unregister_supply_alias(struct device *dev,
181 const char * const *id, int num_id);
183 int devm_regulator_register_supply_alias(struct device *dev, const char *id,
184 struct device *alias_dev,
185 const char *alias_id);
186 void devm_regulator_unregister_supply_alias(struct device *dev,
189 int devm_regulator_bulk_register_supply_alias(struct device *dev,
190 const char *const *id,
191 struct device *alias_dev,
192 const char *const *alias_id,
194 void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
195 const char *const *id,
198 /* regulator output control and status */
199 int __must_check regulator_enable(struct regulator *regulator);
200 int regulator_disable(struct regulator *regulator);
201 int regulator_force_disable(struct regulator *regulator);
202 int regulator_is_enabled(struct regulator *regulator);
203 int regulator_disable_deferred(struct regulator *regulator, int ms);
205 int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
206 struct regulator_bulk_data *consumers);
207 int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
208 struct regulator_bulk_data *consumers);
209 int __must_check regulator_bulk_enable(int num_consumers,
210 struct regulator_bulk_data *consumers);
211 int regulator_bulk_disable(int num_consumers,
212 struct regulator_bulk_data *consumers);
213 int regulator_bulk_force_disable(int num_consumers,
214 struct regulator_bulk_data *consumers);
215 void regulator_bulk_free(int num_consumers,
216 struct regulator_bulk_data *consumers);
218 int regulator_can_change_voltage(struct regulator *regulator);
219 int regulator_count_voltages(struct regulator *regulator);
220 int regulator_list_voltage(struct regulator *regulator, unsigned selector);
221 int regulator_is_supported_voltage(struct regulator *regulator,
222 int min_uV, int max_uV);
223 unsigned int regulator_get_linear_step(struct regulator *regulator);
224 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
225 int regulator_set_voltage_time(struct regulator *regulator,
226 int old_uV, int new_uV);
227 int regulator_get_voltage(struct regulator *regulator);
228 int regulator_sync_voltage(struct regulator *regulator);
229 int regulator_set_current_limit(struct regulator *regulator,
230 int min_uA, int max_uA);
231 int regulator_get_current_limit(struct regulator *regulator);
233 int regulator_set_mode(struct regulator *regulator, unsigned int mode);
234 unsigned int regulator_get_mode(struct regulator *regulator);
235 int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
237 int regulator_allow_bypass(struct regulator *regulator, bool allow);
239 struct regmap *regulator_get_regmap(struct regulator *regulator);
240 int regulator_get_hardware_vsel_register(struct regulator *regulator,
242 unsigned *vsel_mask);
243 int regulator_list_hardware_vsel(struct regulator *regulator,
246 /* regulator notifier block */
247 int regulator_register_notifier(struct regulator *regulator,
248 struct notifier_block *nb);
249 int regulator_unregister_notifier(struct regulator *regulator,
250 struct notifier_block *nb);
252 /* driver data - core doesn't touch */
253 void *regulator_get_drvdata(struct regulator *regulator);
254 void regulator_set_drvdata(struct regulator *regulator, void *data);
259 * Make sure client drivers will still build on systems with no software
260 * controllable voltage or current regulators.
262 static inline struct regulator *__must_check regulator_get(struct device *dev,
265 /* Nothing except the stubbed out regulator API should be
266 * looking at the value except to check if it is an error
267 * value. Drivers are free to handle NULL specifically by
268 * skipping all regulator API calls, but they don't have to.
269 * Drivers which don't, should make sure they properly handle
270 * corner cases of the API, such as regulator_get_voltage()
276 static inline struct regulator *__must_check
277 devm_regulator_get(struct device *dev, const char *id)
282 static inline struct regulator *__must_check
283 regulator_get_exclusive(struct device *dev, const char *id)
288 static inline struct regulator *__must_check
289 regulator_get_optional(struct device *dev, const char *id)
291 return ERR_PTR(-ENODEV);
295 static inline struct regulator *__must_check
296 devm_regulator_get_optional(struct device *dev, const char *id)
298 return ERR_PTR(-ENODEV);
301 static inline void regulator_put(struct regulator *regulator)
305 static inline void devm_regulator_put(struct regulator *regulator)
309 static inline int regulator_register_supply_alias(struct device *dev,
311 struct device *alias_dev,
312 const char *alias_id)
317 static inline void regulator_unregister_supply_alias(struct device *dev,
322 static inline int regulator_bulk_register_supply_alias(struct device *dev,
323 const char *const *id,
324 struct device *alias_dev,
325 const char * const *alias_id,
331 static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
332 const char * const *id,
337 static inline int devm_regulator_register_supply_alias(struct device *dev,
339 struct device *alias_dev,
340 const char *alias_id)
345 static inline void devm_regulator_unregister_supply_alias(struct device *dev,
350 static inline int devm_regulator_bulk_register_supply_alias(struct device *dev,
351 const char *const *id,
352 struct device *alias_dev,
353 const char *const *alias_id,
359 static inline void devm_regulator_bulk_unregister_supply_alias(
360 struct device *dev, const char *const *id, int num_id)
364 static inline int regulator_enable(struct regulator *regulator)
369 static inline int regulator_disable(struct regulator *regulator)
374 static inline int regulator_force_disable(struct regulator *regulator)
379 static inline int regulator_disable_deferred(struct regulator *regulator,
385 static inline int regulator_is_enabled(struct regulator *regulator)
390 static inline int regulator_bulk_get(struct device *dev,
392 struct regulator_bulk_data *consumers)
397 static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
398 struct regulator_bulk_data *consumers)
403 static inline int regulator_bulk_enable(int num_consumers,
404 struct regulator_bulk_data *consumers)
409 static inline int regulator_bulk_disable(int num_consumers,
410 struct regulator_bulk_data *consumers)
415 static inline int regulator_bulk_force_disable(int num_consumers,
416 struct regulator_bulk_data *consumers)
421 static inline void regulator_bulk_free(int num_consumers,
422 struct regulator_bulk_data *consumers)
426 static inline int regulator_can_change_voltage(struct regulator *regulator)
431 static inline int regulator_set_voltage(struct regulator *regulator,
432 int min_uV, int max_uV)
437 static inline int regulator_set_voltage_time(struct regulator *regulator,
438 int old_uV, int new_uV)
443 static inline int regulator_get_voltage(struct regulator *regulator)
448 static inline int regulator_is_supported_voltage(struct regulator *regulator,
449 int min_uV, int max_uV)
454 static inline int regulator_set_current_limit(struct regulator *regulator,
455 int min_uA, int max_uA)
460 static inline int regulator_get_current_limit(struct regulator *regulator)
465 static inline int regulator_set_mode(struct regulator *regulator,
471 static inline unsigned int regulator_get_mode(struct regulator *regulator)
473 return REGULATOR_MODE_NORMAL;
476 static inline int regulator_set_optimum_mode(struct regulator *regulator,
479 return REGULATOR_MODE_NORMAL;
482 static inline int regulator_allow_bypass(struct regulator *regulator,
488 static inline struct regmap *regulator_get_regmap(struct regulator *regulator)
490 return ERR_PTR(-EOPNOTSUPP);
493 static inline int regulator_get_hardware_vsel_register(struct regulator *regulator,
500 static inline int regulator_list_hardware_vsel(struct regulator *regulator,
506 static inline int regulator_register_notifier(struct regulator *regulator,
507 struct notifier_block *nb)
512 static inline int regulator_unregister_notifier(struct regulator *regulator,
513 struct notifier_block *nb)
518 static inline void *regulator_get_drvdata(struct regulator *regulator)
523 static inline void regulator_set_drvdata(struct regulator *regulator,
528 static inline int regulator_count_voltages(struct regulator *regulator)
534 static inline int regulator_set_voltage_tol(struct regulator *regulator,
535 int new_uV, int tol_uV)
537 if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
540 return regulator_set_voltage(regulator,
541 new_uV - tol_uV, new_uV + tol_uV);
544 static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
545 int target_uV, int tol_uV)
547 return regulator_is_supported_voltage(regulator,