~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/regulator/consumer.h

Version: ~ [ linux-5.15-rc7 ] ~ [ linux-5.14.14 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.75 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.155 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.213 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.252 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.287 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.289 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * consumer.h -- SoC Regulator consumer support.
  3  *
  4  * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
  5  *
  6  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  7  *
  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 
 38 #include <linux/err.h>
 39 
 40 struct device;
 41 struct notifier_block;
 42 struct regmap;
 43 
 44 /*
 45  * Regulator operating modes.
 46  *
 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.
 50  *
 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.
 54  *
 55  * In order of power efficiency (least efficient at top).
 56  *
 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.
 61  *
 62  *  NORMAL     Normal regulator power supply mode. Most drivers will
 63  *             use this mode.
 64  *
 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.
 70  *
 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.
 76  *
 77  * NOTE: Most regulators will only support a subset of these modes. Some
 78  * will only just support NORMAL.
 79  *
 80  * These modes can be OR'ed together to make up a mask of valid register modes.
 81  */
 82 
 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 notifier events.
 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  * 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
106  *
107  * NOTE: These events can be OR'ed together when passed into handler.
108  */
109 
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
123 
124 /*
125  * Regulator errors that can be queried using regulator_get_error_flags
126  *
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.
132  *
133  * NOTE: These errors can be OR'ed together.
134  */
135 
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)
141 
142 
143 /**
144  * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
145  *
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.
149  */
150 struct pre_voltage_change_data {
151         unsigned long old_uV;
152         unsigned long min_uV;
153         unsigned long max_uV;
154 };
155 
156 struct regulator;
157 
158 /**
159  * struct regulator_bulk_data - Data used for bulk regulator operations.
160  *
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.
165  *
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.
169  */
170 struct regulator_bulk_data {
171         const char *supply;
172         struct regulator *consumer;
173 
174         /* private: Internal use */
175         int ret;
176 };
177 
178 #if defined(CONFIG_REGULATOR)
179 
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);
195 
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);
200 
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);
208 
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);
214 
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);
223 
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);
230 
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);
243 
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);
257 
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);
263 
264 int regulator_allow_bypass(struct regulator *regulator, bool allow);
265 
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);
272 
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);
282 
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);
286 
287 #else
288 
289 /*
290  * Make sure client drivers will still build on systems with no software
291  * controllable voltage or current regulators.
292  */
293 static inline struct regulator *__must_check regulator_get(struct device *dev,
294         const char *id)
295 {
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.
303          */
304         return NULL;
305 }
306 
307 static inline struct regulator *__must_check
308 devm_regulator_get(struct device *dev, const char *id)
309 {
310         return NULL;
311 }
312 
313 static inline struct regulator *__must_check
314 regulator_get_exclusive(struct device *dev, const char *id)
315 {
316         return ERR_PTR(-ENODEV);
317 }
318 
319 static inline struct regulator *__must_check
320 regulator_get_optional(struct device *dev, const char *id)
321 {
322         return ERR_PTR(-ENODEV);
323 }
324 
325 
326 static inline struct regulator *__must_check
327 devm_regulator_get_optional(struct device *dev, const char *id)
328 {
329         return ERR_PTR(-ENODEV);
330 }
331 
332 static inline void regulator_put(struct regulator *regulator)
333 {
334 }
335 
336 static inline void devm_regulator_put(struct regulator *regulator)
337 {
338 }
339 
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)
344 {
345         return 0;
346 }
347 
348 static inline void regulator_unregister_supply_alias(struct device *dev,
349                                                     const char *id)
350 {
351 }
352 
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)
358 {
359         return 0;
360 }
361 
362 static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
363                                                 const char * const *id,
364                                                 int num_id)
365 {
366 }
367 
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)
372 {
373         return 0;
374 }
375 
376 static inline void devm_regulator_unregister_supply_alias(struct device *dev,
377                                                           const char *id)
378 {
379 }
380 
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)
386 {
387         return 0;
388 }
389 
390 static inline void devm_regulator_bulk_unregister_supply_alias(
391         struct device *dev, const char *const *id, int num_id)
392 {
393 }
394 
395 static inline int regulator_enable(struct regulator *regulator)
396 {
397         return 0;
398 }
399 
400 static inline int regulator_disable(struct regulator *regulator)
401 {
402         return 0;
403 }
404 
405 static inline int regulator_force_disable(struct regulator *regulator)
406 {
407         return 0;
408 }
409 
410 static inline int regulator_disable_deferred(struct regulator *regulator,
411                                              int ms)
412 {
413         return 0;
414 }
415 
416 static inline int regulator_is_enabled(struct regulator *regulator)
417 {
418         return 1;
419 }
420 
421 static inline int regulator_bulk_get(struct device *dev,
422                                      int num_consumers,
423                                      struct regulator_bulk_data *consumers)
424 {
425         return 0;
426 }
427 
428 static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers,
429                                           struct regulator_bulk_data *consumers)
430 {
431         return 0;
432 }
433 
434 static inline int regulator_bulk_enable(int num_consumers,
435                                         struct regulator_bulk_data *consumers)
436 {
437         return 0;
438 }
439 
440 static inline int regulator_bulk_disable(int num_consumers,
441                                          struct regulator_bulk_data *consumers)
442 {
443         return 0;
444 }
445 
446 static inline int regulator_bulk_force_disable(int num_consumers,
447                                         struct regulator_bulk_data *consumers)
448 {
449         return 0;
450 }
451 
452 static inline void regulator_bulk_free(int num_consumers,
453                                        struct regulator_bulk_data *consumers)
454 {
455 }
456 
457 static inline int regulator_set_voltage(struct regulator *regulator,
458                                         int min_uV, int max_uV)
459 {
460         return 0;
461 }
462 
463 static inline int regulator_set_voltage_time(struct regulator *regulator,
464                                              int old_uV, int new_uV)
465 {
466         return 0;
467 }
468 
469 static inline int regulator_get_voltage(struct regulator *regulator)
470 {
471         return -EINVAL;
472 }
473 
474 static inline int regulator_is_supported_voltage(struct regulator *regulator,
475                                    int min_uV, int max_uV)
476 {
477         return 0;
478 }
479 
480 static inline int regulator_set_current_limit(struct regulator *regulator,
481                                              int min_uA, int max_uA)
482 {
483         return 0;
484 }
485 
486 static inline int regulator_get_current_limit(struct regulator *regulator)
487 {
488         return 0;
489 }
490 
491 static inline int regulator_set_mode(struct regulator *regulator,
492         unsigned int mode)
493 {
494         return 0;
495 }
496 
497 static inline unsigned int regulator_get_mode(struct regulator *regulator)
498 {
499         return REGULATOR_MODE_NORMAL;
500 }
501 
502 static inline int regulator_get_error_flags(struct regulator *regulator,
503                                             unsigned int *flags)
504 {
505         return -EINVAL;
506 }
507 
508 static inline int regulator_set_load(struct regulator *regulator, int load_uA)
509 {
510         return REGULATOR_MODE_NORMAL;
511 }
512 
513 static inline int regulator_allow_bypass(struct regulator *regulator,
514                                          bool allow)
515 {
516         return 0;
517 }
518 
519 static inline struct regmap *regulator_get_regmap(struct regulator *regulator)
520 {
521         return ERR_PTR(-EOPNOTSUPP);
522 }
523 
524 static inline int regulator_get_hardware_vsel_register(struct regulator *regulator,
525                                                        unsigned *vsel_reg,
526                                                        unsigned *vsel_mask)
527 {
528         return -EOPNOTSUPP;
529 }
530 
531 static inline int regulator_list_hardware_vsel(struct regulator *regulator,
532                                                unsigned selector)
533 {
534         return -EOPNOTSUPP;
535 }
536 
537 static inline int regulator_register_notifier(struct regulator *regulator,
538                               struct notifier_block *nb)
539 {
540         return 0;
541 }
542 
543 static inline int devm_regulator_register_notifier(struct regulator *regulator,
544                                                    struct notifier_block *nb)
545 {
546         return 0;
547 }
548 
549 static inline int regulator_unregister_notifier(struct regulator *regulator,
550                                 struct notifier_block *nb)
551 {
552         return 0;
553 }
554 
555 static inline int devm_regulator_unregister_notifier(struct regulator *regulator,
556                                                      struct notifier_block *nb)
557 {
558         return 0;
559 }
560 
561 static inline void *regulator_get_drvdata(struct regulator *regulator)
562 {
563         return NULL;
564 }
565 
566 static inline void regulator_set_drvdata(struct regulator *regulator,
567         void *data)
568 {
569 }
570 
571 static inline int regulator_count_voltages(struct regulator *regulator)
572 {
573         return 0;
574 }
575 
576 static inline int regulator_list_voltage(struct regulator *regulator, unsigned selector)
577 {
578         return -EINVAL;
579 }
580 
581 #endif
582 
583 static inline int regulator_set_voltage_triplet(struct regulator *regulator,
584                                                 int min_uV, int target_uV,
585                                                 int max_uV)
586 {
587         if (regulator_set_voltage(regulator, target_uV, max_uV) == 0)
588                 return 0;
589 
590         return regulator_set_voltage(regulator, min_uV, max_uV);
591 }
592 
593 static inline int regulator_set_voltage_tol(struct regulator *regulator,
594                                             int new_uV, int tol_uV)
595 {
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);
601 }
602 
603 static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
604                                                      int target_uV, int tol_uV)
605 {
606         return regulator_is_supported_voltage(regulator,
607                                               target_uV - tol_uV,
608                                               target_uV + tol_uV);
609 }
610 
611 #endif
612 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp