xref: /linux/include/linux/regulator/consumer.h (revision b999e7f92e24e32a785934e5c561c0999e8c14bb)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * consumer.h -- SoC Regulator consumer support.
4  *
5  * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
6  *
7  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8  *
9  * Regulator Consumer Interface.
10  *
11  * A Power Management Regulator framework for SoC based devices.
12  * Features:-
13  *   o Voltage and current level control.
14  *   o Operating mode control.
15  *   o Regulator status.
16  *   o sysfs entries for showing client devices and status
17  *
18  * EXPERIMENTAL FEATURES:
19  *   Dynamic Regulator operating Mode Switching (DRMS) - allows regulators
20  *   to use most efficient operating mode depending upon voltage and load and
21  *   is transparent to client drivers.
22  *
23  *   e.g. Devices x,y,z share regulator r. Device x and y draw 20mA each during
24  *   IO and 1mA at idle. Device z draws 100mA when under load and 5mA when
25  *   idling. Regulator r has > 90% efficiency in NORMAL mode at loads > 100mA
26  *   but this drops rapidly to 60% when below 100mA. Regulator r has > 90%
27  *   efficiency in IDLE mode at loads < 10mA. Thus regulator r will operate
28  *   in normal mode for loads > 10mA and in IDLE mode for load <= 10mA.
29  */
30 
31 #ifndef __LINUX_REGULATOR_CONSUMER_H_
32 #define __LINUX_REGULATOR_CONSUMER_H_
33 
34 #include <linux/err.h>
35 #include <linux/suspend.h>
36 #include <regulator/regulator.h>
37 
38 struct device;
39 struct notifier_block;
40 struct regmap;
41 struct regulator_dev;
42 
43 /*
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_INVALID			0x0
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 errors that can be queried using regulator_get_error_flags
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.
96  *
97  * NOTE: These errors can be OR'ed together.
98  */
99 
100 #define REGULATOR_ERROR_UNDER_VOLTAGE		BIT(1)
101 #define REGULATOR_ERROR_OVER_CURRENT		BIT(2)
102 #define REGULATOR_ERROR_REGULATION_OUT		BIT(3)
103 #define REGULATOR_ERROR_FAIL			BIT(4)
104 #define REGULATOR_ERROR_OVER_TEMP		BIT(5)
105 
106 #define REGULATOR_ERROR_UNDER_VOLTAGE_WARN	BIT(6)
107 #define REGULATOR_ERROR_OVER_CURRENT_WARN	BIT(7)
108 #define REGULATOR_ERROR_OVER_VOLTAGE_WARN	BIT(8)
109 #define REGULATOR_ERROR_OVER_TEMP_WARN		BIT(9)
110 
111 /**
112  * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
113  *
114  * @old_uV: Current voltage before change.
115  * @min_uV: Min voltage we'll change to.
116  * @max_uV: Max voltage we'll change to.
117  */
118 struct pre_voltage_change_data {
119 	unsigned long old_uV;
120 	unsigned long min_uV;
121 	unsigned long max_uV;
122 };
123 
124 struct regulator;
125 
126 /**
127  * struct regulator_bulk_data - Data used for bulk regulator operations.
128  *
129  * @supply:       The name of the supply.  Initialised by the user before
130  *                using the bulk regulator APIs.
131  * @consumer:     The regulator consumer for the supply.  This will be managed
132  *                by the bulk API.
133  * @init_load_uA: After getting the regulator, regulator_set_load() will be
134  *                called with this load.  Initialised by the user before
135  *                using the bulk regulator APIs.
136  *
137  * The regulator APIs provide a series of regulator_bulk_() API calls as
138  * a convenience to consumers which require multiple supplies.  This
139  * structure is used to manage data for these calls.
140  */
141 struct regulator_bulk_data {
142 	const char *supply;
143 	struct regulator *consumer;
144 	int init_load_uA;
145 
146 	/* private: Internal use */
147 	int ret;
148 };
149 
150 #if defined(CONFIG_REGULATOR)
151 
152 /* regulator get and put */
153 struct regulator *__must_check regulator_get(struct device *dev,
154 					     const char *id);
155 struct regulator *__must_check devm_regulator_get(struct device *dev,
156 					     const char *id);
157 struct regulator *__must_check regulator_get_exclusive(struct device *dev,
158 						       const char *id);
159 struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
160 							const char *id);
161 struct regulator *__must_check regulator_get_optional(struct device *dev,
162 						      const char *id);
163 struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
164 							   const char *id);
165 int devm_regulator_get_enable(struct device *dev, const char *id);
166 int devm_regulator_get_enable_optional(struct device *dev, const char *id);
167 int devm_regulator_get_enable_read_voltage(struct device *dev, const char *id);
168 void regulator_put(struct regulator *regulator);
169 void devm_regulator_put(struct regulator *regulator);
170 
171 int regulator_register_supply_alias(struct device *dev, const char *id,
172 				    struct device *alias_dev,
173 				    const char *alias_id);
174 void regulator_unregister_supply_alias(struct device *dev, const char *id);
175 
176 int regulator_bulk_register_supply_alias(struct device *dev,
177 					 const char *const *id,
178 					 struct device *alias_dev,
179 					 const char *const *alias_id,
180 					 int num_id);
181 void regulator_bulk_unregister_supply_alias(struct device *dev,
182 					    const char * const *id, int num_id);
183 
184 int devm_regulator_register_supply_alias(struct device *dev, const char *id,
185 					 struct device *alias_dev,
186 					 const char *alias_id);
187 
188 int devm_regulator_bulk_register_supply_alias(struct device *dev,
189 					      const char *const *id,
190 					      struct device *alias_dev,
191 					      const char *const *alias_id,
192 					      int num_id);
193 
194 /* regulator output control and status */
195 int __must_check regulator_enable(struct regulator *regulator);
196 int regulator_disable(struct regulator *regulator);
197 int regulator_force_disable(struct regulator *regulator);
198 int regulator_is_enabled(struct regulator *regulator);
199 int regulator_disable_deferred(struct regulator *regulator, int ms);
200 
201 int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
202 				    struct regulator_bulk_data *consumers);
203 int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
204 					 struct regulator_bulk_data *consumers);
205 void devm_regulator_bulk_put(struct regulator_bulk_data *consumers);
206 int __must_check devm_regulator_bulk_get_exclusive(struct device *dev, int num_consumers,
207 						   struct regulator_bulk_data *consumers);
208 int __must_check devm_regulator_bulk_get_const(
209 	struct device *dev, int num_consumers,
210 	const struct regulator_bulk_data *in_consumers,
211 	struct regulator_bulk_data **out_consumers);
212 int __must_check regulator_bulk_enable(int num_consumers,
213 				       struct regulator_bulk_data *consumers);
214 int devm_regulator_bulk_get_enable(struct device *dev, int num_consumers,
215 				   const char * const *id);
216 int regulator_bulk_disable(int num_consumers,
217 			   struct regulator_bulk_data *consumers);
218 int regulator_bulk_force_disable(int num_consumers,
219 			   struct regulator_bulk_data *consumers);
220 void regulator_bulk_free(int num_consumers,
221 			 struct regulator_bulk_data *consumers);
222 
223 int regulator_count_voltages(struct regulator *regulator);
224 int regulator_list_voltage(struct regulator *regulator, unsigned selector);
225 int regulator_is_supported_voltage(struct regulator *regulator,
226 				   int min_uV, int max_uV);
227 unsigned int regulator_get_linear_step(struct regulator *regulator);
228 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
229 int regulator_set_voltage_time(struct regulator *regulator,
230 			       int old_uV, int new_uV);
231 int regulator_get_voltage(struct regulator *regulator);
232 int regulator_sync_voltage(struct regulator *regulator);
233 int regulator_set_current_limit(struct regulator *regulator,
234 			       int min_uA, int max_uA);
235 int regulator_get_current_limit(struct regulator *regulator);
236 
237 int regulator_set_mode(struct regulator *regulator, unsigned int mode);
238 unsigned int regulator_get_mode(struct regulator *regulator);
239 int regulator_get_error_flags(struct regulator *regulator,
240 				unsigned int *flags);
241 int regulator_set_load(struct regulator *regulator, int load_uA);
242 
243 int regulator_allow_bypass(struct regulator *regulator, bool allow);
244 
245 struct regmap *regulator_get_regmap(struct regulator *regulator);
246 int regulator_get_hardware_vsel_register(struct regulator *regulator,
247 					 unsigned *vsel_reg,
248 					 unsigned *vsel_mask);
249 int regulator_list_hardware_vsel(struct regulator *regulator,
250 				 unsigned selector);
251 int regulator_hardware_enable(struct regulator *regulator, bool enable);
252 
253 /* regulator notifier block */
254 int regulator_register_notifier(struct regulator *regulator,
255 			      struct notifier_block *nb);
256 int devm_regulator_register_notifier(struct regulator *regulator,
257 				     struct notifier_block *nb);
258 int regulator_unregister_notifier(struct regulator *regulator,
259 				struct notifier_block *nb);
260 void devm_regulator_unregister_notifier(struct regulator *regulator,
261 					struct notifier_block *nb);
262 
263 /* regulator suspend */
264 int regulator_suspend_enable(struct regulator_dev *rdev,
265 			     suspend_state_t state);
266 int regulator_suspend_disable(struct regulator_dev *rdev,
267 			      suspend_state_t state);
268 int regulator_set_suspend_voltage(struct regulator *regulator, int min_uV,
269 				  int max_uV, suspend_state_t state);
270 
271 /* driver data - core doesn't touch */
272 void *regulator_get_drvdata(struct regulator *regulator);
273 void regulator_set_drvdata(struct regulator *regulator, void *data);
274 
275 /* misc helpers */
276 
277 void regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers,
278 				     const char *const *supply_names,
279 				     unsigned int num_supplies);
280 
281 bool regulator_is_equal(struct regulator *reg1, struct regulator *reg2);
282 
283 #else
284 
285 /*
286  * Make sure client drivers will still build on systems with no software
287  * controllable voltage or current regulators.
288  */
regulator_get(struct device * dev,const char * id)289 static inline struct regulator *__must_check regulator_get(struct device *dev,
290 	const char *id)
291 {
292 	/* Nothing except the stubbed out regulator API should be
293 	 * looking at the value except to check if it is an error
294 	 * value. Drivers are free to handle NULL specifically by
295 	 * skipping all regulator API calls, but they don't have to.
296 	 * Drivers which don't, should make sure they properly handle
297 	 * corner cases of the API, such as regulator_get_voltage()
298 	 * returning 0.
299 	 */
300 	return NULL;
301 }
302 
303 static inline struct regulator *__must_check
devm_regulator_get(struct device * dev,const char * id)304 devm_regulator_get(struct device *dev, const char *id)
305 {
306 	return NULL;
307 }
308 
309 static inline struct regulator *__must_check
regulator_get_exclusive(struct device * dev,const char * id)310 regulator_get_exclusive(struct device *dev, const char *id)
311 {
312 	return ERR_PTR(-ENODEV);
313 }
314 
315 static inline struct regulator *__must_check
devm_regulator_get_exclusive(struct device * dev,const char * id)316 devm_regulator_get_exclusive(struct device *dev, const char *id)
317 {
318 	return ERR_PTR(-ENODEV);
319 }
320 
devm_regulator_get_enable(struct device * dev,const char * id)321 static inline int devm_regulator_get_enable(struct device *dev, const char *id)
322 {
323 	return 0;
324 }
325 
devm_regulator_get_enable_optional(struct device * dev,const char * id)326 static inline int devm_regulator_get_enable_optional(struct device *dev,
327 						     const char *id)
328 {
329 	return 0;
330 }
331 
devm_regulator_get_enable_read_voltage(struct device * dev,const char * id)332 static inline int devm_regulator_get_enable_read_voltage(struct device *dev,
333 							 const char *id)
334 {
335 	return -ENODEV;
336 }
337 
338 static inline struct regulator *__must_check
regulator_get_optional(struct device * dev,const char * id)339 regulator_get_optional(struct device *dev, const char *id)
340 {
341 	return ERR_PTR(-ENODEV);
342 }
343 
344 
345 static inline struct regulator *__must_check
devm_regulator_get_optional(struct device * dev,const char * id)346 devm_regulator_get_optional(struct device *dev, const char *id)
347 {
348 	return ERR_PTR(-ENODEV);
349 }
350 
regulator_put(struct regulator * regulator)351 static inline void regulator_put(struct regulator *regulator)
352 {
353 }
354 
devm_regulator_put(struct regulator * regulator)355 static inline void devm_regulator_put(struct regulator *regulator)
356 {
357 }
358 
devm_regulator_bulk_put(struct regulator_bulk_data * consumers)359 static inline void devm_regulator_bulk_put(struct regulator_bulk_data *consumers)
360 {
361 }
362 
regulator_register_supply_alias(struct device * dev,const char * id,struct device * alias_dev,const char * alias_id)363 static inline int regulator_register_supply_alias(struct device *dev,
364 						  const char *id,
365 						  struct device *alias_dev,
366 						  const char *alias_id)
367 {
368 	return 0;
369 }
370 
regulator_unregister_supply_alias(struct device * dev,const char * id)371 static inline void regulator_unregister_supply_alias(struct device *dev,
372 						    const char *id)
373 {
374 }
375 
regulator_bulk_register_supply_alias(struct device * dev,const char * const * id,struct device * alias_dev,const char * const * alias_id,int num_id)376 static inline int regulator_bulk_register_supply_alias(struct device *dev,
377 						const char *const *id,
378 						struct device *alias_dev,
379 						const char * const *alias_id,
380 						int num_id)
381 {
382 	return 0;
383 }
384 
regulator_bulk_unregister_supply_alias(struct device * dev,const char * const * id,int num_id)385 static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
386 						const char * const *id,
387 						int num_id)
388 {
389 }
390 
devm_regulator_register_supply_alias(struct device * dev,const char * id,struct device * alias_dev,const char * alias_id)391 static inline int devm_regulator_register_supply_alias(struct device *dev,
392 						       const char *id,
393 						       struct device *alias_dev,
394 						       const char *alias_id)
395 {
396 	return 0;
397 }
398 
devm_regulator_bulk_register_supply_alias(struct device * dev,const char * const * id,struct device * alias_dev,const char * const * alias_id,int num_id)399 static inline int devm_regulator_bulk_register_supply_alias(struct device *dev,
400 						const char *const *id,
401 						struct device *alias_dev,
402 						const char *const *alias_id,
403 						int num_id)
404 {
405 	return 0;
406 }
407 
regulator_enable(struct regulator * regulator)408 static inline int regulator_enable(struct regulator *regulator)
409 {
410 	return 0;
411 }
412 
regulator_disable(struct regulator * regulator)413 static inline int regulator_disable(struct regulator *regulator)
414 {
415 	return 0;
416 }
417 
regulator_force_disable(struct regulator * regulator)418 static inline int regulator_force_disable(struct regulator *regulator)
419 {
420 	return 0;
421 }
422 
regulator_disable_deferred(struct regulator * regulator,int ms)423 static inline int regulator_disable_deferred(struct regulator *regulator,
424 					     int ms)
425 {
426 	return 0;
427 }
428 
regulator_is_enabled(struct regulator * regulator)429 static inline int regulator_is_enabled(struct regulator *regulator)
430 {
431 	return 1;
432 }
433 
regulator_bulk_get(struct device * dev,int num_consumers,struct regulator_bulk_data * consumers)434 static inline int regulator_bulk_get(struct device *dev,
435 				     int num_consumers,
436 				     struct regulator_bulk_data *consumers)
437 {
438 	return 0;
439 }
440 
devm_regulator_bulk_get(struct device * dev,int num_consumers,struct regulator_bulk_data * consumers)441 static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
442 					  struct regulator_bulk_data *consumers)
443 {
444 	return 0;
445 }
446 
devm_regulator_bulk_get_const(struct device * dev,int num_consumers,const struct regulator_bulk_data * in_consumers,struct regulator_bulk_data ** out_consumers)447 static inline int devm_regulator_bulk_get_const(
448 	struct device *dev, int num_consumers,
449 	const struct regulator_bulk_data *in_consumers,
450 	struct regulator_bulk_data **out_consumers)
451 {
452 	return 0;
453 }
454 
regulator_bulk_enable(int num_consumers,struct regulator_bulk_data * consumers)455 static inline int regulator_bulk_enable(int num_consumers,
456 					struct regulator_bulk_data *consumers)
457 {
458 	return 0;
459 }
460 
devm_regulator_bulk_get_enable(struct device * dev,int num_consumers,const char * const * id)461 static inline int devm_regulator_bulk_get_enable(struct device *dev,
462 						 int num_consumers,
463 						 const char * const *id)
464 {
465 	return 0;
466 }
467 
regulator_bulk_disable(int num_consumers,struct regulator_bulk_data * consumers)468 static inline int regulator_bulk_disable(int num_consumers,
469 					 struct regulator_bulk_data *consumers)
470 {
471 	return 0;
472 }
473 
regulator_bulk_force_disable(int num_consumers,struct regulator_bulk_data * consumers)474 static inline int regulator_bulk_force_disable(int num_consumers,
475 					struct regulator_bulk_data *consumers)
476 {
477 	return 0;
478 }
479 
regulator_bulk_free(int num_consumers,struct regulator_bulk_data * consumers)480 static inline void regulator_bulk_free(int num_consumers,
481 				       struct regulator_bulk_data *consumers)
482 {
483 }
484 
regulator_set_voltage(struct regulator * regulator,int min_uV,int max_uV)485 static inline int regulator_set_voltage(struct regulator *regulator,
486 					int min_uV, int max_uV)
487 {
488 	return 0;
489 }
490 
regulator_set_voltage_time(struct regulator * regulator,int old_uV,int new_uV)491 static inline int regulator_set_voltage_time(struct regulator *regulator,
492 					     int old_uV, int new_uV)
493 {
494 	return 0;
495 }
496 
regulator_get_voltage(struct regulator * regulator)497 static inline int regulator_get_voltage(struct regulator *regulator)
498 {
499 	return -EINVAL;
500 }
501 
regulator_sync_voltage(struct regulator * regulator)502 static inline int regulator_sync_voltage(struct regulator *regulator)
503 {
504 	return -EINVAL;
505 }
506 
regulator_is_supported_voltage(struct regulator * regulator,int min_uV,int max_uV)507 static inline int regulator_is_supported_voltage(struct regulator *regulator,
508 				   int min_uV, int max_uV)
509 {
510 	return 0;
511 }
512 
regulator_get_linear_step(struct regulator * regulator)513 static inline unsigned int regulator_get_linear_step(struct regulator *regulator)
514 {
515 	return 0;
516 }
517 
regulator_set_current_limit(struct regulator * regulator,int min_uA,int max_uA)518 static inline int regulator_set_current_limit(struct regulator *regulator,
519 					     int min_uA, int max_uA)
520 {
521 	return 0;
522 }
523 
regulator_get_current_limit(struct regulator * regulator)524 static inline int regulator_get_current_limit(struct regulator *regulator)
525 {
526 	return 0;
527 }
528 
regulator_set_mode(struct regulator * regulator,unsigned int mode)529 static inline int regulator_set_mode(struct regulator *regulator,
530 	unsigned int mode)
531 {
532 	return 0;
533 }
534 
regulator_get_mode(struct regulator * regulator)535 static inline unsigned int regulator_get_mode(struct regulator *regulator)
536 {
537 	return REGULATOR_MODE_NORMAL;
538 }
539 
regulator_get_error_flags(struct regulator * regulator,unsigned int * flags)540 static inline int regulator_get_error_flags(struct regulator *regulator,
541 					    unsigned int *flags)
542 {
543 	return -EINVAL;
544 }
545 
regulator_set_load(struct regulator * regulator,int load_uA)546 static inline int regulator_set_load(struct regulator *regulator, int load_uA)
547 {
548 	return 0;
549 }
550 
regulator_allow_bypass(struct regulator * regulator,bool allow)551 static inline int regulator_allow_bypass(struct regulator *regulator,
552 					 bool allow)
553 {
554 	return 0;
555 }
556 
regulator_get_regmap(struct regulator * regulator)557 static inline struct regmap *regulator_get_regmap(struct regulator *regulator)
558 {
559 	return ERR_PTR(-EOPNOTSUPP);
560 }
561 
regulator_get_hardware_vsel_register(struct regulator * regulator,unsigned * vsel_reg,unsigned * vsel_mask)562 static inline int regulator_get_hardware_vsel_register(struct regulator *regulator,
563 						       unsigned *vsel_reg,
564 						       unsigned *vsel_mask)
565 {
566 	return -EOPNOTSUPP;
567 }
568 
regulator_list_hardware_vsel(struct regulator * regulator,unsigned selector)569 static inline int regulator_list_hardware_vsel(struct regulator *regulator,
570 					       unsigned selector)
571 {
572 	return -EOPNOTSUPP;
573 }
574 
regulator_hardware_enable(struct regulator * regulator,bool enable)575 static inline int regulator_hardware_enable(struct regulator *regulator,
576 					    bool enable)
577 {
578 	return -EOPNOTSUPP;
579 }
580 
regulator_register_notifier(struct regulator * regulator,struct notifier_block * nb)581 static inline int regulator_register_notifier(struct regulator *regulator,
582 			      struct notifier_block *nb)
583 {
584 	return 0;
585 }
586 
devm_regulator_register_notifier(struct regulator * regulator,struct notifier_block * nb)587 static inline int devm_regulator_register_notifier(struct regulator *regulator,
588 						   struct notifier_block *nb)
589 {
590 	return 0;
591 }
592 
regulator_unregister_notifier(struct regulator * regulator,struct notifier_block * nb)593 static inline int regulator_unregister_notifier(struct regulator *regulator,
594 				struct notifier_block *nb)
595 {
596 	return 0;
597 }
598 
devm_regulator_unregister_notifier(struct regulator * regulator,struct notifier_block * nb)599 static inline int devm_regulator_unregister_notifier(struct regulator *regulator,
600 						     struct notifier_block *nb)
601 {
602 	return 0;
603 }
604 
regulator_suspend_enable(struct regulator_dev * rdev,suspend_state_t state)605 static inline int regulator_suspend_enable(struct regulator_dev *rdev,
606 					   suspend_state_t state)
607 {
608 	return -EINVAL;
609 }
610 
regulator_suspend_disable(struct regulator_dev * rdev,suspend_state_t state)611 static inline int regulator_suspend_disable(struct regulator_dev *rdev,
612 					    suspend_state_t state)
613 {
614 	return -EINVAL;
615 }
616 
regulator_set_suspend_voltage(struct regulator * regulator,int min_uV,int max_uV,suspend_state_t state)617 static inline int regulator_set_suspend_voltage(struct regulator *regulator,
618 						int min_uV, int max_uV,
619 						suspend_state_t state)
620 {
621 	return -EINVAL;
622 }
623 
regulator_get_drvdata(struct regulator * regulator)624 static inline void *regulator_get_drvdata(struct regulator *regulator)
625 {
626 	return NULL;
627 }
628 
regulator_set_drvdata(struct regulator * regulator,void * data)629 static inline void regulator_set_drvdata(struct regulator *regulator,
630 	void *data)
631 {
632 }
633 
regulator_count_voltages(struct regulator * regulator)634 static inline int regulator_count_voltages(struct regulator *regulator)
635 {
636 	return 0;
637 }
638 
regulator_list_voltage(struct regulator * regulator,unsigned selector)639 static inline int regulator_list_voltage(struct regulator *regulator, unsigned selector)
640 {
641 	return -EINVAL;
642 }
643 
644 static inline void
regulator_bulk_set_supply_names(struct regulator_bulk_data * consumers,const char * const * supply_names,unsigned int num_supplies)645 regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers,
646 				const char *const *supply_names,
647 				unsigned int num_supplies)
648 {
649 }
650 
651 static inline bool
regulator_is_equal(struct regulator * reg1,struct regulator * reg2)652 regulator_is_equal(struct regulator *reg1, struct regulator *reg2)
653 {
654 	return false;
655 }
656 #endif
657 
658 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_REGULATOR)
659 struct regulator *__must_check of_regulator_get_optional(struct device *dev,
660 							 struct device_node *node,
661 							 const char *id);
662 struct regulator *__must_check devm_of_regulator_get_optional(struct device *dev,
663 							      struct device_node *node,
664 							      const char *id);
665 int __must_check of_regulator_bulk_get_all(struct device *dev, struct device_node *np,
666 					   struct regulator_bulk_data **consumers);
667 #else
of_regulator_get_optional(struct device * dev,struct device_node * node,const char * id)668 static inline struct regulator *__must_check of_regulator_get_optional(struct device *dev,
669 								       struct device_node *node,
670 								       const char *id)
671 {
672 	return ERR_PTR(-ENODEV);
673 }
674 
devm_of_regulator_get_optional(struct device * dev,struct device_node * node,const char * id)675 static inline struct regulator *__must_check devm_of_regulator_get_optional(struct device *dev,
676 									    struct device_node *node,
677 									    const char *id)
678 {
679 	return ERR_PTR(-ENODEV);
680 }
681 
of_regulator_bulk_get_all(struct device * dev,struct device_node * np,struct regulator_bulk_data ** consumers)682 static inline int of_regulator_bulk_get_all(struct device *dev, struct device_node *np,
683 					    struct regulator_bulk_data **consumers)
684 {
685 	return 0;
686 }
687 
688 #endif
689 
regulator_set_voltage_triplet(struct regulator * regulator,int min_uV,int target_uV,int max_uV)690 static inline int regulator_set_voltage_triplet(struct regulator *regulator,
691 						int min_uV, int target_uV,
692 						int max_uV)
693 {
694 	if (regulator_set_voltage(regulator, target_uV, max_uV) == 0)
695 		return 0;
696 
697 	return regulator_set_voltage(regulator, min_uV, max_uV);
698 }
699 
regulator_set_voltage_tol(struct regulator * regulator,int new_uV,int tol_uV)700 static inline int regulator_set_voltage_tol(struct regulator *regulator,
701 					    int new_uV, int tol_uV)
702 {
703 	if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
704 		return 0;
705 	else
706 		return regulator_set_voltage(regulator,
707 					     new_uV - tol_uV, new_uV + tol_uV);
708 }
709 
regulator_is_supported_voltage_tol(struct regulator * regulator,int target_uV,int tol_uV)710 static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
711 						     int target_uV, int tol_uV)
712 {
713 	return regulator_is_supported_voltage(regulator,
714 					      target_uV - tol_uV,
715 					      target_uV + tol_uV);
716 }
717 
718 #endif
719