blob: 23c72674d7f964a8c331566afa4812c9367deb26 [file] [log] [blame]
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +01001/*
2 * consumer.h -- SoC Regulator consumer support.
3 *
4 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
5 *
Liam Girdwood1dd68f02009-02-02 21:43:31 +00006 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +01007 *
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
Steve Mucklef132c6c2012-06-06 18:30:57 -070038#include <linux/compiler.h>
39
Paul Gortmaker313162d2012-01-30 11:46:54 -050040struct device;
41struct notifier_block;
Liam Girdwoodb56daf12009-11-11 14:16:10 +000042
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +010043/*
44 * Regulator operating modes.
45 *
46 * Regulators can run in a variety of different operating modes depending on
47 * output load. This allows further system power savings by selecting the
48 * best (and most efficient) regulator mode for a desired load.
49 *
50 * Most drivers will only care about NORMAL. The modes below are generic and
51 * will probably not match the naming convention of your regulator data sheet
52 * but should match the use cases in the datasheet.
53 *
54 * In order of power efficiency (least efficient at top).
55 *
56 * Mode Description
57 * FAST Regulator can handle fast changes in it's load.
58 * e.g. useful in CPU voltage & frequency scaling where
59 * load can quickly increase with CPU frequency increases.
60 *
61 * NORMAL Normal regulator power supply mode. Most drivers will
62 * use this mode.
63 *
64 * IDLE Regulator runs in a more efficient mode for light
65 * loads. Can be used for devices that have a low power
66 * requirement during periods of inactivity. This mode
67 * may be more noisy than NORMAL and may not be able
68 * to handle fast load switching.
69 *
70 * STANDBY Regulator runs in the most efficient mode for very
71 * light loads. Can be used by devices when they are
72 * in a sleep/standby state. This mode is likely to be
73 * the most noisy and may not be able to handle fast load
74 * switching.
75 *
76 * NOTE: Most regulators will only support a subset of these modes. Some
77 * will only just support NORMAL.
78 *
79 * These modes can be OR'ed together to make up a mask of valid register modes.
80 */
81
82#define REGULATOR_MODE_FAST 0x1
83#define REGULATOR_MODE_NORMAL 0x2
84#define REGULATOR_MODE_IDLE 0x4
85#define REGULATOR_MODE_STANDBY 0x8
86
87/*
88 * Regulator notifier events.
89 *
90 * UNDER_VOLTAGE Regulator output is under voltage.
91 * OVER_CURRENT Regulator output current is too high.
92 * REGULATION_OUT Regulator output is out of regulation.
93 * FAIL Regulator output has failed.
94 * OVER_TEMP Regulator over temp.
Mark Brown84b68262009-12-01 21:12:27 +000095 * FORCE_DISABLE Regulator forcibly shut down by software.
Jonathan Cameronb136fb42009-01-19 18:20:58 +000096 * VOLTAGE_CHANGE Regulator voltage changed.
Mark Brown84b68262009-12-01 21:12:27 +000097 * DISABLE Regulator was disabled.
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +010098 *
99 * NOTE: These events can be OR'ed together when passed into handler.
100 */
101
102#define REGULATOR_EVENT_UNDER_VOLTAGE 0x01
103#define REGULATOR_EVENT_OVER_CURRENT 0x02
104#define REGULATOR_EVENT_REGULATION_OUT 0x04
105#define REGULATOR_EVENT_FAIL 0x08
106#define REGULATOR_EVENT_OVER_TEMP 0x10
107#define REGULATOR_EVENT_FORCE_DISABLE 0x20
Jonathan Cameronb136fb42009-01-19 18:20:58 +0000108#define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40
Mark Brown84b68262009-12-01 21:12:27 +0000109#define REGULATOR_EVENT_DISABLE 0x80
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100110
111struct regulator;
112
113/**
114 * struct regulator_bulk_data - Data used for bulk regulator operations.
115 *
Mark Brown69279fb2008-12-31 12:52:41 +0000116 * @supply: The name of the supply. Initialised by the user before
117 * using the bulk regulator APIs.
118 * @consumer: The regulator consumer for the supply. This will be managed
119 * by the bulk API.
Justin Paupore1d17cf52011-08-16 15:39:01 -0700120 * @min_uV: The minimum requested voltage for the regulator (in microvolts),
121 * or 0 to not set a voltage.
122 * @max_uV: The maximum requested voltage for the regulator (in microvolts),
123 * or 0 to use @min_uV.
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100124 *
125 * The regulator APIs provide a series of regulator_bulk_() API calls as
126 * a convenience to consumers which require multiple supplies. This
127 * structure is used to manage data for these calls.
128 */
129struct regulator_bulk_data {
130 const char *supply;
131 struct regulator *consumer;
Justin Paupore1d17cf52011-08-16 15:39:01 -0700132 int min_uV;
133 int max_uV;
Mark Brownf21e0e82011-05-24 08:12:40 +0800134
Randy Dunlapbff747c2011-09-08 10:16:47 -0700135 /* private: Internal use */
Mark Brownf21e0e82011-05-24 08:12:40 +0800136 int ret;
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100137};
138
139#if defined(CONFIG_REGULATOR)
140
141/* regulator get and put */
142struct regulator *__must_check regulator_get(struct device *dev,
143 const char *id);
Stephen Boyd070b9072012-01-16 19:39:58 -0800144struct regulator *__must_check devm_regulator_get(struct device *dev,
145 const char *id);
Mark Brown5ffbd132009-07-21 16:00:23 +0100146struct regulator *__must_check regulator_get_exclusive(struct device *dev,
147 const char *id);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100148void regulator_put(struct regulator *regulator);
Axel Lin2950c4b2012-01-29 17:52:37 +0800149void devm_regulator_put(struct regulator *regulator);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100150
151/* regulator output control and status */
152int regulator_enable(struct regulator *regulator);
153int regulator_disable(struct regulator *regulator);
154int regulator_force_disable(struct regulator *regulator);
155int regulator_is_enabled(struct regulator *regulator);
Mark Brownda07ecd2011-09-11 09:53:50 +0100156int regulator_disable_deferred(struct regulator *regulator, int ms);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100157
158int regulator_bulk_get(struct device *dev, int num_consumers,
159 struct regulator_bulk_data *consumers);
Mark Browne6e74032012-01-20 20:10:08 +0000160int devm_regulator_bulk_get(struct device *dev, int num_consumers,
161 struct regulator_bulk_data *consumers);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100162int regulator_bulk_enable(int num_consumers,
163 struct regulator_bulk_data *consumers);
Justin Paupore1d17cf52011-08-16 15:39:01 -0700164int regulator_bulk_set_voltage(int num_consumers,
165 struct regulator_bulk_data *consumers);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100166int regulator_bulk_disable(int num_consumers,
167 struct regulator_bulk_data *consumers);
Donggeun Kime1de2f42012-01-03 16:22:03 +0900168int regulator_bulk_force_disable(int num_consumers,
169 struct regulator_bulk_data *consumers);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100170void regulator_bulk_free(int num_consumers,
171 struct regulator_bulk_data *consumers);
172
David Brownell4367cfd2009-02-26 11:48:36 -0800173int regulator_count_voltages(struct regulator *regulator);
174int regulator_list_voltage(struct regulator *regulator, unsigned selector);
Mark Browna7a1ad92009-07-21 16:00:24 +0100175int regulator_is_supported_voltage(struct regulator *regulator,
176 int min_uV, int max_uV);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100177int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
Linus Walleij88cd2222011-03-17 13:24:52 +0100178int regulator_set_voltage_time(struct regulator *regulator,
179 int old_uV, int new_uV);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100180int regulator_get_voltage(struct regulator *regulator);
Mark Brown606a2562010-12-16 15:49:36 +0000181int regulator_sync_voltage(struct regulator *regulator);
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100182int regulator_set_current_limit(struct regulator *regulator,
183 int min_uA, int max_uA);
184int regulator_get_current_limit(struct regulator *regulator);
185
186int regulator_set_mode(struct regulator *regulator, unsigned int mode);
187unsigned int regulator_get_mode(struct regulator *regulator);
188int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
189
190/* regulator notifier block */
191int regulator_register_notifier(struct regulator *regulator,
192 struct notifier_block *nb);
193int regulator_unregister_notifier(struct regulator *regulator,
194 struct notifier_block *nb);
195
196/* driver data - core doesn't touch */
197void *regulator_get_drvdata(struct regulator *regulator);
198void regulator_set_drvdata(struct regulator *regulator, void *data);
199
200#else
201
202/*
203 * Make sure client drivers will still build on systems with no software
204 * controllable voltage or current regulators.
205 */
206static inline struct regulator *__must_check regulator_get(struct device *dev,
207 const char *id)
208{
209 /* Nothing except the stubbed out regulator API should be
210 * looking at the value except to check if it is an error
Jean Delvarebe1a50d2010-04-03 17:37:45 +0200211 * value. Drivers are free to handle NULL specifically by
212 * skipping all regulator API calls, but they don't have to.
213 * Drivers which don't, should make sure they properly handle
214 * corner cases of the API, such as regulator_get_voltage()
215 * returning 0.
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100216 */
Jean Delvarebe1a50d2010-04-03 17:37:45 +0200217 return NULL;
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100218}
Stephen Boyd070b9072012-01-16 19:39:58 -0800219
220static inline struct regulator *__must_check
221devm_regulator_get(struct device *dev, const char *id)
222{
223 return NULL;
224}
225
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100226static inline void regulator_put(struct regulator *regulator)
227{
228}
229
Axel Lin2950c4b2012-01-29 17:52:37 +0800230static inline void devm_regulator_put(struct regulator *regulator)
231{
232}
233
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100234static inline int regulator_enable(struct regulator *regulator)
235{
236 return 0;
237}
238
239static inline int regulator_disable(struct regulator *regulator)
240{
241 return 0;
242}
243
MyungJoo Ham935a5212012-01-02 18:49:32 +0900244static inline int regulator_force_disable(struct regulator *regulator)
245{
246 return 0;
247}
248
Mark Brownda07ecd2011-09-11 09:53:50 +0100249static inline int regulator_disable_deferred(struct regulator *regulator,
250 int ms)
251{
252 return 0;
253}
254
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100255static inline int regulator_is_enabled(struct regulator *regulator)
256{
257 return 1;
258}
259
260static inline int regulator_bulk_get(struct device *dev,
261 int num_consumers,
262 struct regulator_bulk_data *consumers)
263{
264 return 0;
265}
266
Axel Line24abd62012-01-27 12:55:28 +0800267static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
268 struct regulator_bulk_data *consumers)
269{
270 return 0;
271}
272
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100273static inline int regulator_bulk_enable(int num_consumers,
274 struct regulator_bulk_data *consumers)
275{
276 return 0;
277}
278
279static inline int regulator_bulk_disable(int num_consumers,
280 struct regulator_bulk_data *consumers)
281{
282 return 0;
283}
284
Donggeun Kime1de2f42012-01-03 16:22:03 +0900285static inline int regulator_bulk_force_disable(int num_consumers,
286 struct regulator_bulk_data *consumers)
287{
288 return 0;
289}
290
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100291static inline void regulator_bulk_free(int num_consumers,
292 struct regulator_bulk_data *consumers)
293{
294}
295
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700296static inline int regulator_count_voltages(struct regulator *regulator)
297{
298 return 0;
299}
300
Liam Girdwoode2ce4ea2008-04-30 15:10:07 +0100301static inline int regulator_set_voltage(struct regulator *regulator,
302 int min_uV, int max_uV)
303{
304 return 0;
305}
306
307static inline int regulator_get_voltage(struct regulator *regulator)
308{
309 return 0;
310}
311
312static inline int regulator_set_current_limit(struct regulator *regulator,
313 int min_uA, int max_uA)
314{
315 return 0;
316}
317
318static inline int regulator_get_current_limit(struct regulator *regulator)
319{
320 return 0;
321}
322
323static inline int regulator_set_mode(struct regulator *regulator,
324 unsigned int mode)
325{
326 return 0;
327}
328
329static inline unsigned int regulator_get_mode(struct regulator *regulator)
330{
331 return REGULATOR_MODE_NORMAL;
332}
333
334static inline int regulator_set_optimum_mode(struct regulator *regulator,
335 int load_uA)
336{
337 return REGULATOR_MODE_NORMAL;
338}
339
340static inline int regulator_register_notifier(struct regulator *regulator,
341 struct notifier_block *nb)
342{
343 return 0;
344}
345
346static inline int regulator_unregister_notifier(struct regulator *regulator,
347 struct notifier_block *nb)
348{
349 return 0;
350}
351
352static inline void *regulator_get_drvdata(struct regulator *regulator)
353{
354 return NULL;
355}
356
357static inline void regulator_set_drvdata(struct regulator *regulator,
358 void *data)
359{
360}
361
362#endif
363
364#endif