2 * core.c -- Voltage/Current Regulator framework.
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 * Copyright 2008 SlimLogic Ltd.
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/device.h>
19 #include <linux/err.h>
20 #include <linux/mutex.h>
21 #include <linux/suspend.h>
22 #include <linux/delay.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/regulator/driver.h>
25 #include <linux/regulator/machine.h>
29 #define REGULATOR_VERSION "0.5"
31 static DEFINE_MUTEX(regulator_list_mutex
);
32 static LIST_HEAD(regulator_list
);
33 static LIST_HEAD(regulator_map_list
);
34 static int has_full_constraints
;
37 * struct regulator_map
39 * Used to provide symbolic supply names to devices.
41 struct regulator_map
{
42 struct list_head list
;
43 const char *dev_name
; /* The dev_name() for the consumer */
45 struct regulator_dev
*regulator
;
51 * One for each consumer device.
55 struct list_head list
;
60 struct device_attribute dev_attr
;
61 struct regulator_dev
*rdev
;
64 static int _regulator_is_enabled(struct regulator_dev
*rdev
);
65 static int _regulator_disable(struct regulator_dev
*rdev
);
66 static int _regulator_get_voltage(struct regulator_dev
*rdev
);
67 static int _regulator_get_current_limit(struct regulator_dev
*rdev
);
68 static unsigned int _regulator_get_mode(struct regulator_dev
*rdev
);
69 static void _notifier_call_chain(struct regulator_dev
*rdev
,
70 unsigned long event
, void *data
);
72 static const char *rdev_get_name(struct regulator_dev
*rdev
)
74 if (rdev
->constraints
&& rdev
->constraints
->name
)
75 return rdev
->constraints
->name
;
76 else if (rdev
->desc
->name
)
77 return rdev
->desc
->name
;
82 /* gets the regulator for a given consumer device */
83 static struct regulator
*get_device_regulator(struct device
*dev
)
85 struct regulator
*regulator
= NULL
;
86 struct regulator_dev
*rdev
;
88 mutex_lock(®ulator_list_mutex
);
89 list_for_each_entry(rdev
, ®ulator_list
, list
) {
90 mutex_lock(&rdev
->mutex
);
91 list_for_each_entry(regulator
, &rdev
->consumer_list
, list
) {
92 if (regulator
->dev
== dev
) {
93 mutex_unlock(&rdev
->mutex
);
94 mutex_unlock(®ulator_list_mutex
);
98 mutex_unlock(&rdev
->mutex
);
100 mutex_unlock(®ulator_list_mutex
);
104 /* Platform voltage constraint check */
105 static int regulator_check_voltage(struct regulator_dev
*rdev
,
106 int *min_uV
, int *max_uV
)
108 BUG_ON(*min_uV
> *max_uV
);
110 if (!rdev
->constraints
) {
111 printk(KERN_ERR
"%s: no constraints for %s\n", __func__
,
112 rdev_get_name(rdev
));
115 if (!(rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_VOLTAGE
)) {
116 printk(KERN_ERR
"%s: operation not allowed for %s\n",
117 __func__
, rdev_get_name(rdev
));
121 if (*max_uV
> rdev
->constraints
->max_uV
)
122 *max_uV
= rdev
->constraints
->max_uV
;
123 if (*min_uV
< rdev
->constraints
->min_uV
)
124 *min_uV
= rdev
->constraints
->min_uV
;
126 if (*min_uV
> *max_uV
)
132 /* current constraint check */
133 static int regulator_check_current_limit(struct regulator_dev
*rdev
,
134 int *min_uA
, int *max_uA
)
136 BUG_ON(*min_uA
> *max_uA
);
138 if (!rdev
->constraints
) {
139 printk(KERN_ERR
"%s: no constraints for %s\n", __func__
,
140 rdev_get_name(rdev
));
143 if (!(rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_CURRENT
)) {
144 printk(KERN_ERR
"%s: operation not allowed for %s\n",
145 __func__
, rdev_get_name(rdev
));
149 if (*max_uA
> rdev
->constraints
->max_uA
)
150 *max_uA
= rdev
->constraints
->max_uA
;
151 if (*min_uA
< rdev
->constraints
->min_uA
)
152 *min_uA
= rdev
->constraints
->min_uA
;
154 if (*min_uA
> *max_uA
)
160 /* operating mode constraint check */
161 static int regulator_check_mode(struct regulator_dev
*rdev
, int mode
)
164 case REGULATOR_MODE_FAST
:
165 case REGULATOR_MODE_NORMAL
:
166 case REGULATOR_MODE_IDLE
:
167 case REGULATOR_MODE_STANDBY
:
173 if (!rdev
->constraints
) {
174 printk(KERN_ERR
"%s: no constraints for %s\n", __func__
,
175 rdev_get_name(rdev
));
178 if (!(rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_MODE
)) {
179 printk(KERN_ERR
"%s: operation not allowed for %s\n",
180 __func__
, rdev_get_name(rdev
));
183 if (!(rdev
->constraints
->valid_modes_mask
& mode
)) {
184 printk(KERN_ERR
"%s: invalid mode %x for %s\n",
185 __func__
, mode
, rdev_get_name(rdev
));
191 /* dynamic regulator mode switching constraint check */
192 static int regulator_check_drms(struct regulator_dev
*rdev
)
194 if (!rdev
->constraints
) {
195 printk(KERN_ERR
"%s: no constraints for %s\n", __func__
,
196 rdev_get_name(rdev
));
199 if (!(rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_DRMS
)) {
200 printk(KERN_ERR
"%s: operation not allowed for %s\n",
201 __func__
, rdev_get_name(rdev
));
207 static ssize_t
device_requested_uA_show(struct device
*dev
,
208 struct device_attribute
*attr
, char *buf
)
210 struct regulator
*regulator
;
212 regulator
= get_device_regulator(dev
);
213 if (regulator
== NULL
)
216 return sprintf(buf
, "%d\n", regulator
->uA_load
);
219 static ssize_t
regulator_uV_show(struct device
*dev
,
220 struct device_attribute
*attr
, char *buf
)
222 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
225 mutex_lock(&rdev
->mutex
);
226 ret
= sprintf(buf
, "%d\n", _regulator_get_voltage(rdev
));
227 mutex_unlock(&rdev
->mutex
);
231 static DEVICE_ATTR(microvolts
, 0444, regulator_uV_show
, NULL
);
233 static ssize_t
regulator_uA_show(struct device
*dev
,
234 struct device_attribute
*attr
, char *buf
)
236 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
238 return sprintf(buf
, "%d\n", _regulator_get_current_limit(rdev
));
240 static DEVICE_ATTR(microamps
, 0444, regulator_uA_show
, NULL
);
242 static ssize_t
regulator_name_show(struct device
*dev
,
243 struct device_attribute
*attr
, char *buf
)
245 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
247 return sprintf(buf
, "%s\n", rdev_get_name(rdev
));
250 static ssize_t
regulator_print_opmode(char *buf
, int mode
)
253 case REGULATOR_MODE_FAST
:
254 return sprintf(buf
, "fast\n");
255 case REGULATOR_MODE_NORMAL
:
256 return sprintf(buf
, "normal\n");
257 case REGULATOR_MODE_IDLE
:
258 return sprintf(buf
, "idle\n");
259 case REGULATOR_MODE_STANDBY
:
260 return sprintf(buf
, "standby\n");
262 return sprintf(buf
, "unknown\n");
265 static ssize_t
regulator_opmode_show(struct device
*dev
,
266 struct device_attribute
*attr
, char *buf
)
268 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
270 return regulator_print_opmode(buf
, _regulator_get_mode(rdev
));
272 static DEVICE_ATTR(opmode
, 0444, regulator_opmode_show
, NULL
);
274 static ssize_t
regulator_print_state(char *buf
, int state
)
277 return sprintf(buf
, "enabled\n");
279 return sprintf(buf
, "disabled\n");
281 return sprintf(buf
, "unknown\n");
284 static ssize_t
regulator_state_show(struct device
*dev
,
285 struct device_attribute
*attr
, char *buf
)
287 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
290 mutex_lock(&rdev
->mutex
);
291 ret
= regulator_print_state(buf
, _regulator_is_enabled(rdev
));
292 mutex_unlock(&rdev
->mutex
);
296 static DEVICE_ATTR(state
, 0444, regulator_state_show
, NULL
);
298 static ssize_t
regulator_status_show(struct device
*dev
,
299 struct device_attribute
*attr
, char *buf
)
301 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
305 status
= rdev
->desc
->ops
->get_status(rdev
);
310 case REGULATOR_STATUS_OFF
:
313 case REGULATOR_STATUS_ON
:
316 case REGULATOR_STATUS_ERROR
:
319 case REGULATOR_STATUS_FAST
:
322 case REGULATOR_STATUS_NORMAL
:
325 case REGULATOR_STATUS_IDLE
:
328 case REGULATOR_STATUS_STANDBY
:
335 return sprintf(buf
, "%s\n", label
);
337 static DEVICE_ATTR(status
, 0444, regulator_status_show
, NULL
);
339 static ssize_t
regulator_min_uA_show(struct device
*dev
,
340 struct device_attribute
*attr
, char *buf
)
342 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
344 if (!rdev
->constraints
)
345 return sprintf(buf
, "constraint not defined\n");
347 return sprintf(buf
, "%d\n", rdev
->constraints
->min_uA
);
349 static DEVICE_ATTR(min_microamps
, 0444, regulator_min_uA_show
, NULL
);
351 static ssize_t
regulator_max_uA_show(struct device
*dev
,
352 struct device_attribute
*attr
, char *buf
)
354 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
356 if (!rdev
->constraints
)
357 return sprintf(buf
, "constraint not defined\n");
359 return sprintf(buf
, "%d\n", rdev
->constraints
->max_uA
);
361 static DEVICE_ATTR(max_microamps
, 0444, regulator_max_uA_show
, NULL
);
363 static ssize_t
regulator_min_uV_show(struct device
*dev
,
364 struct device_attribute
*attr
, char *buf
)
366 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
368 if (!rdev
->constraints
)
369 return sprintf(buf
, "constraint not defined\n");
371 return sprintf(buf
, "%d\n", rdev
->constraints
->min_uV
);
373 static DEVICE_ATTR(min_microvolts
, 0444, regulator_min_uV_show
, NULL
);
375 static ssize_t
regulator_max_uV_show(struct device
*dev
,
376 struct device_attribute
*attr
, char *buf
)
378 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
380 if (!rdev
->constraints
)
381 return sprintf(buf
, "constraint not defined\n");
383 return sprintf(buf
, "%d\n", rdev
->constraints
->max_uV
);
385 static DEVICE_ATTR(max_microvolts
, 0444, regulator_max_uV_show
, NULL
);
387 static ssize_t
regulator_total_uA_show(struct device
*dev
,
388 struct device_attribute
*attr
, char *buf
)
390 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
391 struct regulator
*regulator
;
394 mutex_lock(&rdev
->mutex
);
395 list_for_each_entry(regulator
, &rdev
->consumer_list
, list
)
396 uA
+= regulator
->uA_load
;
397 mutex_unlock(&rdev
->mutex
);
398 return sprintf(buf
, "%d\n", uA
);
400 static DEVICE_ATTR(requested_microamps
, 0444, regulator_total_uA_show
, NULL
);
402 static ssize_t
regulator_num_users_show(struct device
*dev
,
403 struct device_attribute
*attr
, char *buf
)
405 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
406 return sprintf(buf
, "%d\n", rdev
->use_count
);
409 static ssize_t
regulator_type_show(struct device
*dev
,
410 struct device_attribute
*attr
, char *buf
)
412 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
414 switch (rdev
->desc
->type
) {
415 case REGULATOR_VOLTAGE
:
416 return sprintf(buf
, "voltage\n");
417 case REGULATOR_CURRENT
:
418 return sprintf(buf
, "current\n");
420 return sprintf(buf
, "unknown\n");
423 static ssize_t
regulator_suspend_mem_uV_show(struct device
*dev
,
424 struct device_attribute
*attr
, char *buf
)
426 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
428 return sprintf(buf
, "%d\n", rdev
->constraints
->state_mem
.uV
);
430 static DEVICE_ATTR(suspend_mem_microvolts
, 0444,
431 regulator_suspend_mem_uV_show
, NULL
);
433 static ssize_t
regulator_suspend_disk_uV_show(struct device
*dev
,
434 struct device_attribute
*attr
, char *buf
)
436 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
438 return sprintf(buf
, "%d\n", rdev
->constraints
->state_disk
.uV
);
440 static DEVICE_ATTR(suspend_disk_microvolts
, 0444,
441 regulator_suspend_disk_uV_show
, NULL
);
443 static ssize_t
regulator_suspend_standby_uV_show(struct device
*dev
,
444 struct device_attribute
*attr
, char *buf
)
446 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
448 return sprintf(buf
, "%d\n", rdev
->constraints
->state_standby
.uV
);
450 static DEVICE_ATTR(suspend_standby_microvolts
, 0444,
451 regulator_suspend_standby_uV_show
, NULL
);
453 static ssize_t
regulator_suspend_mem_mode_show(struct device
*dev
,
454 struct device_attribute
*attr
, char *buf
)
456 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
458 return regulator_print_opmode(buf
,
459 rdev
->constraints
->state_mem
.mode
);
461 static DEVICE_ATTR(suspend_mem_mode
, 0444,
462 regulator_suspend_mem_mode_show
, NULL
);
464 static ssize_t
regulator_suspend_disk_mode_show(struct device
*dev
,
465 struct device_attribute
*attr
, char *buf
)
467 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
469 return regulator_print_opmode(buf
,
470 rdev
->constraints
->state_disk
.mode
);
472 static DEVICE_ATTR(suspend_disk_mode
, 0444,
473 regulator_suspend_disk_mode_show
, NULL
);
475 static ssize_t
regulator_suspend_standby_mode_show(struct device
*dev
,
476 struct device_attribute
*attr
, char *buf
)
478 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
480 return regulator_print_opmode(buf
,
481 rdev
->constraints
->state_standby
.mode
);
483 static DEVICE_ATTR(suspend_standby_mode
, 0444,
484 regulator_suspend_standby_mode_show
, NULL
);
486 static ssize_t
regulator_suspend_mem_state_show(struct device
*dev
,
487 struct device_attribute
*attr
, char *buf
)
489 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
491 return regulator_print_state(buf
,
492 rdev
->constraints
->state_mem
.enabled
);
494 static DEVICE_ATTR(suspend_mem_state
, 0444,
495 regulator_suspend_mem_state_show
, NULL
);
497 static ssize_t
regulator_suspend_disk_state_show(struct device
*dev
,
498 struct device_attribute
*attr
, char *buf
)
500 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
502 return regulator_print_state(buf
,
503 rdev
->constraints
->state_disk
.enabled
);
505 static DEVICE_ATTR(suspend_disk_state
, 0444,
506 regulator_suspend_disk_state_show
, NULL
);
508 static ssize_t
regulator_suspend_standby_state_show(struct device
*dev
,
509 struct device_attribute
*attr
, char *buf
)
511 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
513 return regulator_print_state(buf
,
514 rdev
->constraints
->state_standby
.enabled
);
516 static DEVICE_ATTR(suspend_standby_state
, 0444,
517 regulator_suspend_standby_state_show
, NULL
);
521 * These are the only attributes are present for all regulators.
522 * Other attributes are a function of regulator functionality.
524 static struct device_attribute regulator_dev_attrs
[] = {
525 __ATTR(name
, 0444, regulator_name_show
, NULL
),
526 __ATTR(num_users
, 0444, regulator_num_users_show
, NULL
),
527 __ATTR(type
, 0444, regulator_type_show
, NULL
),
531 static void regulator_dev_release(struct device
*dev
)
533 struct regulator_dev
*rdev
= dev_get_drvdata(dev
);
537 static struct class regulator_class
= {
539 .dev_release
= regulator_dev_release
,
540 .dev_attrs
= regulator_dev_attrs
,
543 /* Calculate the new optimum regulator operating mode based on the new total
544 * consumer load. All locks held by caller */
545 static void drms_uA_update(struct regulator_dev
*rdev
)
547 struct regulator
*sibling
;
548 int current_uA
= 0, output_uV
, input_uV
, err
;
551 err
= regulator_check_drms(rdev
);
552 if (err
< 0 || !rdev
->desc
->ops
->get_optimum_mode
||
553 !rdev
->desc
->ops
->get_voltage
|| !rdev
->desc
->ops
->set_mode
)
556 /* get output voltage */
557 output_uV
= rdev
->desc
->ops
->get_voltage(rdev
);
561 /* get input voltage */
562 if (rdev
->supply
&& rdev
->supply
->desc
->ops
->get_voltage
)
563 input_uV
= rdev
->supply
->desc
->ops
->get_voltage(rdev
->supply
);
565 input_uV
= rdev
->constraints
->input_uV
;
569 /* calc total requested load */
570 list_for_each_entry(sibling
, &rdev
->consumer_list
, list
)
571 current_uA
+= sibling
->uA_load
;
573 /* now get the optimum mode for our new total regulator load */
574 mode
= rdev
->desc
->ops
->get_optimum_mode(rdev
, input_uV
,
575 output_uV
, current_uA
);
577 /* check the new mode is allowed */
578 err
= regulator_check_mode(rdev
, mode
);
580 rdev
->desc
->ops
->set_mode(rdev
, mode
);
583 static int suspend_set_state(struct regulator_dev
*rdev
,
584 struct regulator_state
*rstate
)
589 can_set_state
= rdev
->desc
->ops
->set_suspend_enable
&&
590 rdev
->desc
->ops
->set_suspend_disable
;
592 /* If we have no suspend mode configration don't set anything;
593 * only warn if the driver actually makes the suspend mode
596 if (!rstate
->enabled
&& !rstate
->disabled
) {
598 printk(KERN_WARNING
"%s: No configuration for %s\n",
599 __func__
, rdev_get_name(rdev
));
603 if (rstate
->enabled
&& rstate
->disabled
) {
604 printk(KERN_ERR
"%s: invalid configuration for %s\n",
605 __func__
, rdev_get_name(rdev
));
609 if (!can_set_state
) {
610 printk(KERN_ERR
"%s: no way to set suspend state\n",
616 ret
= rdev
->desc
->ops
->set_suspend_enable(rdev
);
618 ret
= rdev
->desc
->ops
->set_suspend_disable(rdev
);
620 printk(KERN_ERR
"%s: failed to enabled/disable\n", __func__
);
624 if (rdev
->desc
->ops
->set_suspend_voltage
&& rstate
->uV
> 0) {
625 ret
= rdev
->desc
->ops
->set_suspend_voltage(rdev
, rstate
->uV
);
627 printk(KERN_ERR
"%s: failed to set voltage\n",
633 if (rdev
->desc
->ops
->set_suspend_mode
&& rstate
->mode
> 0) {
634 ret
= rdev
->desc
->ops
->set_suspend_mode(rdev
, rstate
->mode
);
636 printk(KERN_ERR
"%s: failed to set mode\n", __func__
);
643 /* locks held by caller */
644 static int suspend_prepare(struct regulator_dev
*rdev
, suspend_state_t state
)
646 if (!rdev
->constraints
)
650 case PM_SUSPEND_STANDBY
:
651 return suspend_set_state(rdev
,
652 &rdev
->constraints
->state_standby
);
654 return suspend_set_state(rdev
,
655 &rdev
->constraints
->state_mem
);
657 return suspend_set_state(rdev
,
658 &rdev
->constraints
->state_disk
);
664 static void print_constraints(struct regulator_dev
*rdev
)
666 struct regulation_constraints
*constraints
= rdev
->constraints
;
671 if (constraints
->min_uV
&& constraints
->max_uV
) {
672 if (constraints
->min_uV
== constraints
->max_uV
)
673 count
+= sprintf(buf
+ count
, "%d mV ",
674 constraints
->min_uV
/ 1000);
676 count
+= sprintf(buf
+ count
, "%d <--> %d mV ",
677 constraints
->min_uV
/ 1000,
678 constraints
->max_uV
/ 1000);
681 if (!constraints
->min_uV
||
682 constraints
->min_uV
!= constraints
->max_uV
) {
683 ret
= _regulator_get_voltage(rdev
);
685 count
+= sprintf(buf
+ count
, "at %d mV ", ret
/ 1000);
688 if (constraints
->min_uA
&& constraints
->max_uA
) {
689 if (constraints
->min_uA
== constraints
->max_uA
)
690 count
+= sprintf(buf
+ count
, "%d mA ",
691 constraints
->min_uA
/ 1000);
693 count
+= sprintf(buf
+ count
, "%d <--> %d mA ",
694 constraints
->min_uA
/ 1000,
695 constraints
->max_uA
/ 1000);
698 if (!constraints
->min_uA
||
699 constraints
->min_uA
!= constraints
->max_uA
) {
700 ret
= _regulator_get_current_limit(rdev
);
702 count
+= sprintf(buf
+ count
, "at %d uA ", ret
/ 1000);
705 if (constraints
->valid_modes_mask
& REGULATOR_MODE_FAST
)
706 count
+= sprintf(buf
+ count
, "fast ");
707 if (constraints
->valid_modes_mask
& REGULATOR_MODE_NORMAL
)
708 count
+= sprintf(buf
+ count
, "normal ");
709 if (constraints
->valid_modes_mask
& REGULATOR_MODE_IDLE
)
710 count
+= sprintf(buf
+ count
, "idle ");
711 if (constraints
->valid_modes_mask
& REGULATOR_MODE_STANDBY
)
712 count
+= sprintf(buf
+ count
, "standby");
714 printk(KERN_INFO
"regulator: %s: %s\n", rdev_get_name(rdev
), buf
);
717 static int machine_constraints_voltage(struct regulator_dev
*rdev
,
718 struct regulation_constraints
*constraints
)
720 struct regulator_ops
*ops
= rdev
->desc
->ops
;
721 const char *name
= rdev_get_name(rdev
);
724 /* do we need to apply the constraint voltage */
725 if (rdev
->constraints
->apply_uV
&&
726 rdev
->constraints
->min_uV
== rdev
->constraints
->max_uV
&&
728 ret
= ops
->set_voltage(rdev
,
729 rdev
->constraints
->min_uV
, rdev
->constraints
->max_uV
);
731 printk(KERN_ERR
"%s: failed to apply %duV constraint to %s\n",
733 rdev
->constraints
->min_uV
, name
);
734 rdev
->constraints
= NULL
;
739 /* constrain machine-level voltage specs to fit
740 * the actual range supported by this regulator.
742 if (ops
->list_voltage
&& rdev
->desc
->n_voltages
) {
743 int count
= rdev
->desc
->n_voltages
;
745 int min_uV
= INT_MAX
;
746 int max_uV
= INT_MIN
;
747 int cmin
= constraints
->min_uV
;
748 int cmax
= constraints
->max_uV
;
750 /* it's safe to autoconfigure fixed-voltage supplies
751 and the constraints are used by list_voltage. */
752 if (count
== 1 && !cmin
) {
755 constraints
->min_uV
= cmin
;
756 constraints
->max_uV
= cmax
;
759 /* voltage constraints are optional */
760 if ((cmin
== 0) && (cmax
== 0))
763 /* else require explicit machine-level constraints */
764 if (cmin
<= 0 || cmax
<= 0 || cmax
< cmin
) {
765 pr_err("%s: %s '%s' voltage constraints\n",
766 __func__
, "invalid", name
);
770 /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */
771 for (i
= 0; i
< count
; i
++) {
774 value
= ops
->list_voltage(rdev
, i
);
778 /* maybe adjust [min_uV..max_uV] */
779 if (value
>= cmin
&& value
< min_uV
)
781 if (value
<= cmax
&& value
> max_uV
)
785 /* final: [min_uV..max_uV] valid iff constraints valid */
786 if (max_uV
< min_uV
) {
787 pr_err("%s: %s '%s' voltage constraints\n",
788 __func__
, "unsupportable", name
);
792 /* use regulator's subset of machine constraints */
793 if (constraints
->min_uV
< min_uV
) {
794 pr_debug("%s: override '%s' %s, %d -> %d\n",
795 __func__
, name
, "min_uV",
796 constraints
->min_uV
, min_uV
);
797 constraints
->min_uV
= min_uV
;
799 if (constraints
->max_uV
> max_uV
) {
800 pr_debug("%s: override '%s' %s, %d -> %d\n",
801 __func__
, name
, "max_uV",
802 constraints
->max_uV
, max_uV
);
803 constraints
->max_uV
= max_uV
;
811 * set_machine_constraints - sets regulator constraints
812 * @rdev: regulator source
813 * @constraints: constraints to apply
815 * Allows platform initialisation code to define and constrain
816 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
817 * Constraints *must* be set by platform code in order for some
818 * regulator operations to proceed i.e. set_voltage, set_current_limit,
821 static int set_machine_constraints(struct regulator_dev
*rdev
,
822 struct regulation_constraints
*constraints
)
826 struct regulator_ops
*ops
= rdev
->desc
->ops
;
828 rdev
->constraints
= constraints
;
830 name
= rdev_get_name(rdev
);
832 ret
= machine_constraints_voltage(rdev
, constraints
);
836 /* do we need to setup our suspend state */
837 if (constraints
->initial_state
) {
838 ret
= suspend_prepare(rdev
, constraints
->initial_state
);
840 printk(KERN_ERR
"%s: failed to set suspend state for %s\n",
842 rdev
->constraints
= NULL
;
847 if (constraints
->initial_mode
) {
848 if (!ops
->set_mode
) {
849 printk(KERN_ERR
"%s: no set_mode operation for %s\n",
855 ret
= ops
->set_mode(rdev
, constraints
->initial_mode
);
858 "%s: failed to set initial mode for %s: %d\n",
859 __func__
, name
, ret
);
864 /* If the constraints say the regulator should be on at this point
865 * and we have control then make sure it is enabled.
867 if ((constraints
->always_on
|| constraints
->boot_on
) && ops
->enable
) {
868 ret
= ops
->enable(rdev
);
870 printk(KERN_ERR
"%s: failed to enable %s\n",
872 rdev
->constraints
= NULL
;
877 print_constraints(rdev
);
883 * set_supply - set regulator supply regulator
884 * @rdev: regulator name
885 * @supply_rdev: supply regulator name
887 * Called by platform initialisation code to set the supply regulator for this
888 * regulator. This ensures that a regulators supply will also be enabled by the
889 * core if it's child is enabled.
891 static int set_supply(struct regulator_dev
*rdev
,
892 struct regulator_dev
*supply_rdev
)
896 err
= sysfs_create_link(&rdev
->dev
.kobj
, &supply_rdev
->dev
.kobj
,
900 "%s: could not add device link %s err %d\n",
901 __func__
, supply_rdev
->dev
.kobj
.name
, err
);
904 rdev
->supply
= supply_rdev
;
905 list_add(&rdev
->slist
, &supply_rdev
->supply_list
);
911 * set_consumer_device_supply: Bind a regulator to a symbolic supply
912 * @rdev: regulator source
913 * @consumer_dev: device the supply applies to
914 * @consumer_dev_name: dev_name() string for device supply applies to
915 * @supply: symbolic name for supply
917 * Allows platform initialisation code to map physical regulator
918 * sources to symbolic names for supplies for use by devices. Devices
919 * should use these symbolic names to request regulators, avoiding the
920 * need to provide board-specific regulator names as platform data.
922 * Only one of consumer_dev and consumer_dev_name may be specified.
924 static int set_consumer_device_supply(struct regulator_dev
*rdev
,
925 struct device
*consumer_dev
, const char *consumer_dev_name
,
928 struct regulator_map
*node
;
931 if (consumer_dev
&& consumer_dev_name
)
934 if (!consumer_dev_name
&& consumer_dev
)
935 consumer_dev_name
= dev_name(consumer_dev
);
940 if (consumer_dev_name
!= NULL
)
945 list_for_each_entry(node
, ®ulator_map_list
, list
) {
946 if (consumer_dev_name
!= node
->dev_name
)
948 if (strcmp(node
->supply
, supply
) != 0)
951 dev_dbg(consumer_dev
, "%s/%s is '%s' supply; fail %s/%s\n",
952 dev_name(&node
->regulator
->dev
),
953 node
->regulator
->desc
->name
,
955 dev_name(&rdev
->dev
), rdev_get_name(rdev
));
959 node
= kzalloc(sizeof(struct regulator_map
), GFP_KERNEL
);
963 node
->regulator
= rdev
;
964 node
->supply
= supply
;
967 node
->dev_name
= kstrdup(consumer_dev_name
, GFP_KERNEL
);
968 if (node
->dev_name
== NULL
) {
974 list_add(&node
->list
, ®ulator_map_list
);
978 static void unset_consumer_device_supply(struct regulator_dev
*rdev
,
979 const char *consumer_dev_name
, struct device
*consumer_dev
)
981 struct regulator_map
*node
, *n
;
983 if (consumer_dev
&& !consumer_dev_name
)
984 consumer_dev_name
= dev_name(consumer_dev
);
986 list_for_each_entry_safe(node
, n
, ®ulator_map_list
, list
) {
987 if (rdev
!= node
->regulator
)
990 if (consumer_dev_name
&& node
->dev_name
&&
991 strcmp(consumer_dev_name
, node
->dev_name
))
994 list_del(&node
->list
);
995 kfree(node
->dev_name
);
1001 static void unset_regulator_supplies(struct regulator_dev
*rdev
)
1003 struct regulator_map
*node
, *n
;
1005 list_for_each_entry_safe(node
, n
, ®ulator_map_list
, list
) {
1006 if (rdev
== node
->regulator
) {
1007 list_del(&node
->list
);
1008 kfree(node
->dev_name
);
1015 #define REG_STR_SIZE 32
1017 static struct regulator
*create_regulator(struct regulator_dev
*rdev
,
1019 const char *supply_name
)
1021 struct regulator
*regulator
;
1022 char buf
[REG_STR_SIZE
];
1025 regulator
= kzalloc(sizeof(*regulator
), GFP_KERNEL
);
1026 if (regulator
== NULL
)
1029 mutex_lock(&rdev
->mutex
);
1030 regulator
->rdev
= rdev
;
1031 list_add(®ulator
->list
, &rdev
->consumer_list
);
1034 /* create a 'requested_microamps_name' sysfs entry */
1035 size
= scnprintf(buf
, REG_STR_SIZE
, "microamps_requested_%s",
1037 if (size
>= REG_STR_SIZE
)
1040 regulator
->dev
= dev
;
1041 sysfs_attr_init(®ulator
->dev_attr
.attr
);
1042 regulator
->dev_attr
.attr
.name
= kstrdup(buf
, GFP_KERNEL
);
1043 if (regulator
->dev_attr
.attr
.name
== NULL
)
1046 regulator
->dev_attr
.attr
.owner
= THIS_MODULE
;
1047 regulator
->dev_attr
.attr
.mode
= 0444;
1048 regulator
->dev_attr
.show
= device_requested_uA_show
;
1049 err
= device_create_file(dev
, ®ulator
->dev_attr
);
1051 printk(KERN_WARNING
"%s: could not add regulator_dev"
1052 " load sysfs\n", __func__
);
1056 /* also add a link to the device sysfs entry */
1057 size
= scnprintf(buf
, REG_STR_SIZE
, "%s-%s",
1058 dev
->kobj
.name
, supply_name
);
1059 if (size
>= REG_STR_SIZE
)
1062 regulator
->supply_name
= kstrdup(buf
, GFP_KERNEL
);
1063 if (regulator
->supply_name
== NULL
)
1066 err
= sysfs_create_link(&rdev
->dev
.kobj
, &dev
->kobj
,
1070 "%s: could not add device link %s err %d\n",
1071 __func__
, dev
->kobj
.name
, err
);
1072 device_remove_file(dev
, ®ulator
->dev_attr
);
1076 mutex_unlock(&rdev
->mutex
);
1079 kfree(regulator
->supply_name
);
1081 device_remove_file(regulator
->dev
, ®ulator
->dev_attr
);
1083 kfree(regulator
->dev_attr
.attr
.name
);
1085 list_del(®ulator
->list
);
1087 mutex_unlock(&rdev
->mutex
);
1091 static int _regulator_get_enable_time(struct regulator_dev
*rdev
)
1093 if (!rdev
->desc
->ops
->enable_time
)
1095 return rdev
->desc
->ops
->enable_time(rdev
);
1098 /* Internal regulator request function */
1099 static struct regulator
*_regulator_get(struct device
*dev
, const char *id
,
1102 struct regulator_dev
*rdev
;
1103 struct regulator_map
*map
;
1104 struct regulator
*regulator
= ERR_PTR(-ENODEV
);
1105 const char *devname
= NULL
;
1109 printk(KERN_ERR
"regulator: get() with no identifier\n");
1114 devname
= dev_name(dev
);
1116 mutex_lock(®ulator_list_mutex
);
1118 list_for_each_entry(map
, ®ulator_map_list
, list
) {
1119 /* If the mapping has a device set up it must match */
1120 if (map
->dev_name
&&
1121 (!devname
|| strcmp(map
->dev_name
, devname
)))
1124 if (strcmp(map
->supply
, id
) == 0) {
1125 rdev
= map
->regulator
;
1130 #ifdef CONFIG_REGULATOR_DUMMY
1132 devname
= "deviceless";
1134 /* If the board didn't flag that it was fully constrained then
1135 * substitute in a dummy regulator so consumers can continue.
1137 if (!has_full_constraints
) {
1138 pr_warning("%s supply %s not found, using dummy regulator\n",
1140 rdev
= dummy_regulator_rdev
;
1145 mutex_unlock(®ulator_list_mutex
);
1149 if (rdev
->exclusive
) {
1150 regulator
= ERR_PTR(-EPERM
);
1154 if (exclusive
&& rdev
->open_count
) {
1155 regulator
= ERR_PTR(-EBUSY
);
1159 if (!try_module_get(rdev
->owner
))
1162 regulator
= create_regulator(rdev
, dev
, id
);
1163 if (regulator
== NULL
) {
1164 regulator
= ERR_PTR(-ENOMEM
);
1165 module_put(rdev
->owner
);
1170 rdev
->exclusive
= 1;
1172 ret
= _regulator_is_enabled(rdev
);
1174 rdev
->use_count
= 1;
1176 rdev
->use_count
= 0;
1180 mutex_unlock(®ulator_list_mutex
);
1186 * regulator_get - lookup and obtain a reference to a regulator.
1187 * @dev: device for regulator "consumer"
1188 * @id: Supply name or regulator ID.
1190 * Returns a struct regulator corresponding to the regulator producer,
1191 * or IS_ERR() condition containing errno.
1193 * Use of supply names configured via regulator_set_device_supply() is
1194 * strongly encouraged. It is recommended that the supply name used
1195 * should match the name used for the supply and/or the relevant
1196 * device pins in the datasheet.
1198 struct regulator
*regulator_get(struct device
*dev
, const char *id
)
1200 return _regulator_get(dev
, id
, 0);
1202 EXPORT_SYMBOL_GPL(regulator_get
);
1205 * regulator_get_exclusive - obtain exclusive access to a regulator.
1206 * @dev: device for regulator "consumer"
1207 * @id: Supply name or regulator ID.
1209 * Returns a struct regulator corresponding to the regulator producer,
1210 * or IS_ERR() condition containing errno. Other consumers will be
1211 * unable to obtain this reference is held and the use count for the
1212 * regulator will be initialised to reflect the current state of the
1215 * This is intended for use by consumers which cannot tolerate shared
1216 * use of the regulator such as those which need to force the
1217 * regulator off for correct operation of the hardware they are
1220 * Use of supply names configured via regulator_set_device_supply() is
1221 * strongly encouraged. It is recommended that the supply name used
1222 * should match the name used for the supply and/or the relevant
1223 * device pins in the datasheet.
1225 struct regulator
*regulator_get_exclusive(struct device
*dev
, const char *id
)
1227 return _regulator_get(dev
, id
, 1);
1229 EXPORT_SYMBOL_GPL(regulator_get_exclusive
);
1232 * regulator_put - "free" the regulator source
1233 * @regulator: regulator source
1235 * Note: drivers must ensure that all regulator_enable calls made on this
1236 * regulator source are balanced by regulator_disable calls prior to calling
1239 void regulator_put(struct regulator
*regulator
)
1241 struct regulator_dev
*rdev
;
1243 if (regulator
== NULL
|| IS_ERR(regulator
))
1246 mutex_lock(®ulator_list_mutex
);
1247 rdev
= regulator
->rdev
;
1249 /* remove any sysfs entries */
1250 if (regulator
->dev
) {
1251 sysfs_remove_link(&rdev
->dev
.kobj
, regulator
->supply_name
);
1252 kfree(regulator
->supply_name
);
1253 device_remove_file(regulator
->dev
, ®ulator
->dev_attr
);
1254 kfree(regulator
->dev_attr
.attr
.name
);
1256 list_del(®ulator
->list
);
1260 rdev
->exclusive
= 0;
1262 module_put(rdev
->owner
);
1263 mutex_unlock(®ulator_list_mutex
);
1265 EXPORT_SYMBOL_GPL(regulator_put
);
1267 static int _regulator_can_change_status(struct regulator_dev
*rdev
)
1269 if (!rdev
->constraints
)
1272 if (rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_STATUS
)
1278 /* locks held by regulator_enable() */
1279 static int _regulator_enable(struct regulator_dev
*rdev
)
1283 /* do we need to enable the supply regulator first */
1285 ret
= _regulator_enable(rdev
->supply
);
1287 printk(KERN_ERR
"%s: failed to enable %s: %d\n",
1288 __func__
, rdev_get_name(rdev
), ret
);
1293 /* check voltage and requested load before enabling */
1294 if (rdev
->constraints
&&
1295 (rdev
->constraints
->valid_ops_mask
& REGULATOR_CHANGE_DRMS
))
1296 drms_uA_update(rdev
);
1298 if (rdev
->use_count
== 0) {
1299 /* The regulator may on if it's not switchable or left on */
1300 ret
= _regulator_is_enabled(rdev
);
1301 if (ret
== -EINVAL
|| ret
== 0) {
1302 if (!_regulator_can_change_status(rdev
))
1305 if (!rdev
->desc
->ops
->enable
)
1308 /* Query before enabling in case configuration
1310 ret
= _regulator_get_enable_time(rdev
);
1315 "%s: enable_time() failed for %s: %d\n",
1316 __func__
, rdev_get_name(rdev
),
1321 /* Allow the regulator to ramp; it would be useful
1322 * to extend this for bulk operations so that the
1323 * regulators can ramp together. */
1324 ret
= rdev
->desc
->ops
->enable(rdev
);
1329 mdelay(delay
/ 1000);
1333 } else if (ret
< 0) {
1334 printk(KERN_ERR
"%s: is_enabled() failed for %s: %d\n",
1335 __func__
, rdev_get_name(rdev
), ret
);
1338 /* Fallthrough on positive return values - already enabled */
1347 * regulator_enable - enable regulator output
1348 * @regulator: regulator source
1350 * Request that the regulator be enabled with the regulator output at
1351 * the predefined voltage or current value. Calls to regulator_enable()
1352 * must be balanced with calls to regulator_disable().
1354 * NOTE: the output value can be set by other drivers, boot loader or may be
1355 * hardwired in the regulator.
1357 int regulator_enable(struct regulator
*regulator
)
1359 struct regulator_dev
*rdev
= regulator
->rdev
;
1362 mutex_lock(&rdev
->mutex
);
1363 ret
= _regulator_enable(rdev
);
1364 mutex_unlock(&rdev
->mutex
);
1367 EXPORT_SYMBOL_GPL(regulator_enable
);
1369 /* locks held by regulator_disable() */
1370 static int _regulator_disable(struct regulator_dev
*rdev
)
1374 if (WARN(rdev
->use_count
<= 0,
1375 "unbalanced disables for %s\n",
1376 rdev_get_name(rdev
)))
1379 /* are we the last user and permitted to disable ? */
1380 if (rdev
->use_count
== 1 &&
1381 (rdev
->constraints
&& !rdev
->constraints
->always_on
)) {
1383 /* we are last user */
1384 if (_regulator_can_change_status(rdev
) &&
1385 rdev
->desc
->ops
->disable
) {
1386 ret
= rdev
->desc
->ops
->disable(rdev
);
1388 printk(KERN_ERR
"%s: failed to disable %s\n",
1389 __func__
, rdev_get_name(rdev
));
1393 _notifier_call_chain(rdev
, REGULATOR_EVENT_DISABLE
,
1397 /* decrease our supplies ref count and disable if required */
1399 _regulator_disable(rdev
->supply
);
1401 rdev
->use_count
= 0;
1402 } else if (rdev
->use_count
> 1) {
1404 if (rdev
->constraints
&&
1405 (rdev
->constraints
->valid_ops_mask
&
1406 REGULATOR_CHANGE_DRMS
))
1407 drms_uA_update(rdev
);
1415 * regulator_disable - disable regulator output
1416 * @regulator: regulator source
1418 * Disable the regulator output voltage or current. Calls to
1419 * regulator_enable() must be balanced with calls to
1420 * regulator_disable().
1422 * NOTE: this will only disable the regulator output if no other consumer
1423 * devices have it enabled, the regulator device supports disabling and
1424 * machine constraints permit this operation.
1426 int regulator_disable(struct regulator
*regulator
)
1428 struct regulator_dev
*rdev
= regulator
->rdev
;
1431 mutex_lock(&rdev
->mutex
);
1432 ret
= _regulator_disable(rdev
);
1433 mutex_unlock(&rdev
->mutex
);
1436 EXPORT_SYMBOL_GPL(regulator_disable
);
1438 /* locks held by regulator_force_disable() */
1439 static int _regulator_force_disable(struct regulator_dev
*rdev
)
1444 if (rdev
->desc
->ops
->disable
) {
1445 /* ah well, who wants to live forever... */
1446 ret
= rdev
->desc
->ops
->disable(rdev
);
1448 printk(KERN_ERR
"%s: failed to force disable %s\n",
1449 __func__
, rdev_get_name(rdev
));
1452 /* notify other consumers that power has been forced off */
1453 _notifier_call_chain(rdev
, REGULATOR_EVENT_FORCE_DISABLE
|
1454 REGULATOR_EVENT_DISABLE
, NULL
);
1457 /* decrease our supplies ref count and disable if required */
1459 _regulator_disable(rdev
->supply
);
1461 rdev
->use_count
= 0;
1466 * regulator_force_disable - force disable regulator output
1467 * @regulator: regulator source
1469 * Forcibly disable the regulator output voltage or current.
1470 * NOTE: this *will* disable the regulator output even if other consumer
1471 * devices have it enabled. This should be used for situations when device
1472 * damage will likely occur if the regulator is not disabled (e.g. over temp).
1474 int regulator_force_disable(struct regulator
*regulator
)
1478 mutex_lock(®ulator
->rdev
->mutex
);
1479 regulator
->uA_load
= 0;
1480 ret
= _regulator_force_disable(regulator
->rdev
);
1481 mutex_unlock(®ulator
->rdev
->mutex
);
1484 EXPORT_SYMBOL_GPL(regulator_force_disable
);
1486 static int _regulator_is_enabled(struct regulator_dev
*rdev
)
1488 /* If we don't know then assume that the regulator is always on */
1489 if (!rdev
->desc
->ops
->is_enabled
)
1492 return rdev
->desc
->ops
->is_enabled(rdev
);
1496 * regulator_is_enabled - is the regulator output enabled
1497 * @regulator: regulator source
1499 * Returns positive if the regulator driver backing the source/client
1500 * has requested that the device be enabled, zero if it hasn't, else a
1501 * negative errno code.
1503 * Note that the device backing this regulator handle can have multiple
1504 * users, so it might be enabled even if regulator_enable() was never
1505 * called for this particular source.
1507 int regulator_is_enabled(struct regulator
*regulator
)
1511 mutex_lock(®ulator
->rdev
->mutex
);
1512 ret
= _regulator_is_enabled(regulator
->rdev
);
1513 mutex_unlock(®ulator
->rdev
->mutex
);
1517 EXPORT_SYMBOL_GPL(regulator_is_enabled
);
1520 * regulator_count_voltages - count regulator_list_voltage() selectors
1521 * @regulator: regulator source
1523 * Returns number of selectors, or negative errno. Selectors are
1524 * numbered starting at zero, and typically correspond to bitfields
1525 * in hardware registers.
1527 int regulator_count_voltages(struct regulator
*regulator
)
1529 struct regulator_dev
*rdev
= regulator
->rdev
;
1531 return rdev
->desc
->n_voltages
? : -EINVAL
;
1533 EXPORT_SYMBOL_GPL(regulator_count_voltages
);
1536 * regulator_list_voltage - enumerate supported voltages
1537 * @regulator: regulator source
1538 * @selector: identify voltage to list
1539 * Context: can sleep
1541 * Returns a voltage that can be passed to @regulator_set_voltage(),
1542 * zero if this selector code can't be used on this sytem, or a
1545 int regulator_list_voltage(struct regulator
*regulator
, unsigned selector
)
1547 struct regulator_dev
*rdev
= regulator
->rdev
;
1548 struct regulator_ops
*ops
= rdev
->desc
->ops
;
1551 if (!ops
->list_voltage
|| selector
>= rdev
->desc
->n_voltages
)
1554 mutex_lock(&rdev
->mutex
);
1555 ret
= ops
->list_voltage(rdev
, selector
);
1556 mutex_unlock(&rdev
->mutex
);
1559 if (ret
< rdev
->constraints
->min_uV
)
1561 else if (ret
> rdev
->constraints
->max_uV
)
1567 EXPORT_SYMBOL_GPL(regulator_list_voltage
);
1570 * regulator_is_supported_voltage - check if a voltage range can be supported
1572 * @regulator: Regulator to check.
1573 * @min_uV: Minimum required voltage in uV.
1574 * @max_uV: Maximum required voltage in uV.
1576 * Returns a boolean or a negative error code.
1578 int regulator_is_supported_voltage(struct regulator
*regulator
,
1579 int min_uV
, int max_uV
)
1581 int i
, voltages
, ret
;
1583 ret
= regulator_count_voltages(regulator
);
1588 for (i
= 0; i
< voltages
; i
++) {
1589 ret
= regulator_list_voltage(regulator
, i
);
1591 if (ret
>= min_uV
&& ret
<= max_uV
)
1599 * regulator_set_voltage - set regulator output voltage
1600 * @regulator: regulator source
1601 * @min_uV: Minimum required voltage in uV
1602 * @max_uV: Maximum acceptable voltage in uV
1604 * Sets a voltage regulator to the desired output voltage. This can be set
1605 * during any regulator state. IOW, regulator can be disabled or enabled.
1607 * If the regulator is enabled then the voltage will change to the new value
1608 * immediately otherwise if the regulator is disabled the regulator will
1609 * output at the new voltage when enabled.
1611 * NOTE: If the regulator is shared between several devices then the lowest
1612 * request voltage that meets the system constraints will be used.
1613 * Regulator system constraints must be set for this regulator before
1614 * calling this function otherwise this call will fail.
1616 int regulator_set_voltage(struct regulator
*regulator
, int min_uV
, int max_uV
)
1618 struct regulator_dev
*rdev
= regulator
->rdev
;
1621 mutex_lock(&rdev
->mutex
);
1624 if (!rdev
->desc
->ops
->set_voltage
) {
1629 /* constraints check */
1630 ret
= regulator_check_voltage(rdev
, &min_uV
, &max_uV
);
1633 regulator
->min_uV
= min_uV
;
1634 regulator
->max_uV
= max_uV
;
1635 ret
= rdev
->desc
->ops
->set_voltage(rdev
, min_uV
, max_uV
);
1638 _notifier_call_chain(rdev
, REGULATOR_EVENT_VOLTAGE_CHANGE
, NULL
);
1639 mutex_unlock(&rdev
->mutex
);
1642 EXPORT_SYMBOL_GPL(regulator_set_voltage
);
1644 static int _regulator_get_voltage(struct regulator_dev
*rdev
)
1647 if (rdev
->desc
->ops
->get_voltage
)
1648 return rdev
->desc
->ops
->get_voltage(rdev
);
1654 * regulator_get_voltage - get regulator output voltage
1655 * @regulator: regulator source
1657 * This returns the current regulator voltage in uV.
1659 * NOTE: If the regulator is disabled it will return the voltage value. This
1660 * function should not be used to determine regulator state.
1662 int regulator_get_voltage(struct regulator
*regulator
)
1666 mutex_lock(®ulator
->rdev
->mutex
);
1668 ret
= _regulator_get_voltage(regulator
->rdev
);
1670 mutex_unlock(®ulator
->rdev
->mutex
);
1674 EXPORT_SYMBOL_GPL(regulator_get_voltage
);
1677 * regulator_set_current_limit - set regulator output current limit
1678 * @regulator: regulator source
1679 * @min_uA: Minimuum supported current in uA
1680 * @max_uA: Maximum supported current in uA
1682 * Sets current sink to the desired output current. This can be set during
1683 * any regulator state. IOW, regulator can be disabled or enabled.
1685 * If the regulator is enabled then the current will change to the new value
1686 * immediately otherwise if the regulator is disabled the regulator will
1687 * output at the new current when enabled.
1689 * NOTE: Regulator system constraints must be set for this regulator before
1690 * calling this function otherwise this call will fail.
1692 int regulator_set_current_limit(struct regulator
*regulator
,
1693 int min_uA
, int max_uA
)
1695 struct regulator_dev
*rdev
= regulator
->rdev
;
1698 mutex_lock(&rdev
->mutex
);
1701 if (!rdev
->desc
->ops
->set_current_limit
) {
1706 /* constraints check */
1707 ret
= regulator_check_current_limit(rdev
, &min_uA
, &max_uA
);
1711 ret
= rdev
->desc
->ops
->set_current_limit(rdev
, min_uA
, max_uA
);
1713 mutex_unlock(&rdev
->mutex
);
1716 EXPORT_SYMBOL_GPL(regulator_set_current_limit
);
1718 static int _regulator_get_current_limit(struct regulator_dev
*rdev
)
1722 mutex_lock(&rdev
->mutex
);
1725 if (!rdev
->desc
->ops
->get_current_limit
) {
1730 ret
= rdev
->desc
->ops
->get_current_limit(rdev
);
1732 mutex_unlock(&rdev
->mutex
);
1737 * regulator_get_current_limit - get regulator output current
1738 * @regulator: regulator source
1740 * This returns the current supplied by the specified current sink in uA.
1742 * NOTE: If the regulator is disabled it will return the current value. This
1743 * function should not be used to determine regulator state.
1745 int regulator_get_current_limit(struct regulator
*regulator
)
1747 return _regulator_get_current_limit(regulator
->rdev
);
1749 EXPORT_SYMBOL_GPL(regulator_get_current_limit
);
1752 * regulator_set_mode - set regulator operating mode
1753 * @regulator: regulator source
1754 * @mode: operating mode - one of the REGULATOR_MODE constants
1756 * Set regulator operating mode to increase regulator efficiency or improve
1757 * regulation performance.
1759 * NOTE: Regulator system constraints must be set for this regulator before
1760 * calling this function otherwise this call will fail.
1762 int regulator_set_mode(struct regulator
*regulator
, unsigned int mode
)
1764 struct regulator_dev
*rdev
= regulator
->rdev
;
1767 mutex_lock(&rdev
->mutex
);
1770 if (!rdev
->desc
->ops
->set_mode
) {
1775 /* constraints check */
1776 ret
= regulator_check_mode(rdev
, mode
);
1780 ret
= rdev
->desc
->ops
->set_mode(rdev
, mode
);
1782 mutex_unlock(&rdev
->mutex
);
1785 EXPORT_SYMBOL_GPL(regulator_set_mode
);
1787 static unsigned int _regulator_get_mode(struct regulator_dev
*rdev
)
1791 mutex_lock(&rdev
->mutex
);
1794 if (!rdev
->desc
->ops
->get_mode
) {
1799 ret
= rdev
->desc
->ops
->get_mode(rdev
);
1801 mutex_unlock(&rdev
->mutex
);
1806 * regulator_get_mode - get regulator operating mode
1807 * @regulator: regulator source
1809 * Get the current regulator operating mode.
1811 unsigned int regulator_get_mode(struct regulator
*regulator
)
1813 return _regulator_get_mode(regulator
->rdev
);
1815 EXPORT_SYMBOL_GPL(regulator_get_mode
);
1818 * regulator_set_optimum_mode - set regulator optimum operating mode
1819 * @regulator: regulator source
1820 * @uA_load: load current
1822 * Notifies the regulator core of a new device load. This is then used by
1823 * DRMS (if enabled by constraints) to set the most efficient regulator
1824 * operating mode for the new regulator loading.
1826 * Consumer devices notify their supply regulator of the maximum power
1827 * they will require (can be taken from device datasheet in the power
1828 * consumption tables) when they change operational status and hence power
1829 * state. Examples of operational state changes that can affect power
1830 * consumption are :-
1832 * o Device is opened / closed.
1833 * o Device I/O is about to begin or has just finished.
1834 * o Device is idling in between work.
1836 * This information is also exported via sysfs to userspace.
1838 * DRMS will sum the total requested load on the regulator and change
1839 * to the most efficient operating mode if platform constraints allow.
1841 * Returns the new regulator mode or error.
1843 int regulator_set_optimum_mode(struct regulator
*regulator
, int uA_load
)
1845 struct regulator_dev
*rdev
= regulator
->rdev
;
1846 struct regulator
*consumer
;
1847 int ret
, output_uV
, input_uV
, total_uA_load
= 0;
1850 mutex_lock(&rdev
->mutex
);
1852 regulator
->uA_load
= uA_load
;
1853 ret
= regulator_check_drms(rdev
);
1859 if (!rdev
->desc
->ops
->get_optimum_mode
)
1862 /* get output voltage */
1863 output_uV
= rdev
->desc
->ops
->get_voltage(rdev
);
1864 if (output_uV
<= 0) {
1865 printk(KERN_ERR
"%s: invalid output voltage found for %s\n",
1866 __func__
, rdev_get_name(rdev
));
1870 /* get input voltage */
1871 if (rdev
->supply
&& rdev
->supply
->desc
->ops
->get_voltage
)
1872 input_uV
= rdev
->supply
->desc
->ops
->get_voltage(rdev
->supply
);
1874 input_uV
= rdev
->constraints
->input_uV
;
1875 if (input_uV
<= 0) {
1876 printk(KERN_ERR
"%s: invalid input voltage found for %s\n",
1877 __func__
, rdev_get_name(rdev
));
1881 /* calc total requested load for this regulator */
1882 list_for_each_entry(consumer
, &rdev
->consumer_list
, list
)
1883 total_uA_load
+= consumer
->uA_load
;
1885 mode
= rdev
->desc
->ops
->get_optimum_mode(rdev
,
1886 input_uV
, output_uV
,
1888 ret
= regulator_check_mode(rdev
, mode
);
1890 printk(KERN_ERR
"%s: failed to get optimum mode for %s @"
1891 " %d uA %d -> %d uV\n", __func__
, rdev_get_name(rdev
),
1892 total_uA_load
, input_uV
, output_uV
);
1896 ret
= rdev
->desc
->ops
->set_mode(rdev
, mode
);
1898 printk(KERN_ERR
"%s: failed to set optimum mode %x for %s\n",
1899 __func__
, mode
, rdev_get_name(rdev
));
1904 mutex_unlock(&rdev
->mutex
);
1907 EXPORT_SYMBOL_GPL(regulator_set_optimum_mode
);
1910 * regulator_register_notifier - register regulator event notifier
1911 * @regulator: regulator source
1912 * @nb: notifier block
1914 * Register notifier block to receive regulator events.
1916 int regulator_register_notifier(struct regulator
*regulator
,
1917 struct notifier_block
*nb
)
1919 return blocking_notifier_chain_register(®ulator
->rdev
->notifier
,
1922 EXPORT_SYMBOL_GPL(regulator_register_notifier
);
1925 * regulator_unregister_notifier - unregister regulator event notifier
1926 * @regulator: regulator source
1927 * @nb: notifier block
1929 * Unregister regulator event notifier block.
1931 int regulator_unregister_notifier(struct regulator
*regulator
,
1932 struct notifier_block
*nb
)
1934 return blocking_notifier_chain_unregister(®ulator
->rdev
->notifier
,
1937 EXPORT_SYMBOL_GPL(regulator_unregister_notifier
);
1939 /* notify regulator consumers and downstream regulator consumers.
1940 * Note mutex must be held by caller.
1942 static void _notifier_call_chain(struct regulator_dev
*rdev
,
1943 unsigned long event
, void *data
)
1945 struct regulator_dev
*_rdev
;
1947 /* call rdev chain first */
1948 blocking_notifier_call_chain(&rdev
->notifier
, event
, NULL
);
1950 /* now notify regulator we supply */
1951 list_for_each_entry(_rdev
, &rdev
->supply_list
, slist
) {
1952 mutex_lock(&_rdev
->mutex
);
1953 _notifier_call_chain(_rdev
, event
, data
);
1954 mutex_unlock(&_rdev
->mutex
);
1959 * regulator_bulk_get - get multiple regulator consumers
1961 * @dev: Device to supply
1962 * @num_consumers: Number of consumers to register
1963 * @consumers: Configuration of consumers; clients are stored here.
1965 * @return 0 on success, an errno on failure.
1967 * This helper function allows drivers to get several regulator
1968 * consumers in one operation. If any of the regulators cannot be
1969 * acquired then any regulators that were allocated will be freed
1970 * before returning to the caller.
1972 int regulator_bulk_get(struct device
*dev
, int num_consumers
,
1973 struct regulator_bulk_data
*consumers
)
1978 for (i
= 0; i
< num_consumers
; i
++)
1979 consumers
[i
].consumer
= NULL
;
1981 for (i
= 0; i
< num_consumers
; i
++) {
1982 consumers
[i
].consumer
= regulator_get(dev
,
1983 consumers
[i
].supply
);
1984 if (IS_ERR(consumers
[i
].consumer
)) {
1985 ret
= PTR_ERR(consumers
[i
].consumer
);
1986 dev_err(dev
, "Failed to get supply '%s': %d\n",
1987 consumers
[i
].supply
, ret
);
1988 consumers
[i
].consumer
= NULL
;
1996 for (i
= 0; i
< num_consumers
&& consumers
[i
].consumer
; i
++)
1997 regulator_put(consumers
[i
].consumer
);
2001 EXPORT_SYMBOL_GPL(regulator_bulk_get
);
2004 * regulator_bulk_enable - enable multiple regulator consumers
2006 * @num_consumers: Number of consumers
2007 * @consumers: Consumer data; clients are stored here.
2008 * @return 0 on success, an errno on failure
2010 * This convenience API allows consumers to enable multiple regulator
2011 * clients in a single API call. If any consumers cannot be enabled
2012 * then any others that were enabled will be disabled again prior to
2015 int regulator_bulk_enable(int num_consumers
,
2016 struct regulator_bulk_data
*consumers
)
2021 for (i
= 0; i
< num_consumers
; i
++) {
2022 ret
= regulator_enable(consumers
[i
].consumer
);
2030 printk(KERN_ERR
"Failed to enable %s: %d\n", consumers
[i
].supply
, ret
);
2031 for (--i
; i
>= 0; --i
)
2032 regulator_disable(consumers
[i
].consumer
);
2036 EXPORT_SYMBOL_GPL(regulator_bulk_enable
);
2039 * regulator_bulk_disable - disable multiple regulator consumers
2041 * @num_consumers: Number of consumers
2042 * @consumers: Consumer data; clients are stored here.
2043 * @return 0 on success, an errno on failure
2045 * This convenience API allows consumers to disable multiple regulator
2046 * clients in a single API call. If any consumers cannot be enabled
2047 * then any others that were disabled will be disabled again prior to
2050 int regulator_bulk_disable(int num_consumers
,
2051 struct regulator_bulk_data
*consumers
)
2056 for (i
= 0; i
< num_consumers
; i
++) {
2057 ret
= regulator_disable(consumers
[i
].consumer
);
2065 printk(KERN_ERR
"Failed to disable %s: %d\n", consumers
[i
].supply
,
2067 for (--i
; i
>= 0; --i
)
2068 regulator_enable(consumers
[i
].consumer
);
2072 EXPORT_SYMBOL_GPL(regulator_bulk_disable
);
2075 * regulator_bulk_free - free multiple regulator consumers
2077 * @num_consumers: Number of consumers
2078 * @consumers: Consumer data; clients are stored here.
2080 * This convenience API allows consumers to free multiple regulator
2081 * clients in a single API call.
2083 void regulator_bulk_free(int num_consumers
,
2084 struct regulator_bulk_data
*consumers
)
2088 for (i
= 0; i
< num_consumers
; i
++) {
2089 regulator_put(consumers
[i
].consumer
);
2090 consumers
[i
].consumer
= NULL
;
2093 EXPORT_SYMBOL_GPL(regulator_bulk_free
);
2096 * regulator_notifier_call_chain - call regulator event notifier
2097 * @rdev: regulator source
2098 * @event: notifier block
2099 * @data: callback-specific data.
2101 * Called by regulator drivers to notify clients a regulator event has
2102 * occurred. We also notify regulator clients downstream.
2103 * Note lock must be held by caller.
2105 int regulator_notifier_call_chain(struct regulator_dev
*rdev
,
2106 unsigned long event
, void *data
)
2108 _notifier_call_chain(rdev
, event
, data
);
2112 EXPORT_SYMBOL_GPL(regulator_notifier_call_chain
);
2115 * regulator_mode_to_status - convert a regulator mode into a status
2117 * @mode: Mode to convert
2119 * Convert a regulator mode into a status.
2121 int regulator_mode_to_status(unsigned int mode
)
2124 case REGULATOR_MODE_FAST
:
2125 return REGULATOR_STATUS_FAST
;
2126 case REGULATOR_MODE_NORMAL
:
2127 return REGULATOR_STATUS_NORMAL
;
2128 case REGULATOR_MODE_IDLE
:
2129 return REGULATOR_STATUS_IDLE
;
2130 case REGULATOR_STATUS_STANDBY
:
2131 return REGULATOR_STATUS_STANDBY
;
2136 EXPORT_SYMBOL_GPL(regulator_mode_to_status
);
2139 * To avoid cluttering sysfs (and memory) with useless state, only
2140 * create attributes that can be meaningfully displayed.
2142 static int add_regulator_attributes(struct regulator_dev
*rdev
)
2144 struct device
*dev
= &rdev
->dev
;
2145 struct regulator_ops
*ops
= rdev
->desc
->ops
;
2148 /* some attributes need specific methods to be displayed */
2149 if (ops
->get_voltage
) {
2150 status
= device_create_file(dev
, &dev_attr_microvolts
);
2154 if (ops
->get_current_limit
) {
2155 status
= device_create_file(dev
, &dev_attr_microamps
);
2159 if (ops
->get_mode
) {
2160 status
= device_create_file(dev
, &dev_attr_opmode
);
2164 if (ops
->is_enabled
) {
2165 status
= device_create_file(dev
, &dev_attr_state
);
2169 if (ops
->get_status
) {
2170 status
= device_create_file(dev
, &dev_attr_status
);
2175 /* some attributes are type-specific */
2176 if (rdev
->desc
->type
== REGULATOR_CURRENT
) {
2177 status
= device_create_file(dev
, &dev_attr_requested_microamps
);
2182 /* all the other attributes exist to support constraints;
2183 * don't show them if there are no constraints, or if the
2184 * relevant supporting methods are missing.
2186 if (!rdev
->constraints
)
2189 /* constraints need specific supporting methods */
2190 if (ops
->set_voltage
) {
2191 status
= device_create_file(dev
, &dev_attr_min_microvolts
);
2194 status
= device_create_file(dev
, &dev_attr_max_microvolts
);
2198 if (ops
->set_current_limit
) {
2199 status
= device_create_file(dev
, &dev_attr_min_microamps
);
2202 status
= device_create_file(dev
, &dev_attr_max_microamps
);
2207 /* suspend mode constraints need multiple supporting methods */
2208 if (!(ops
->set_suspend_enable
&& ops
->set_suspend_disable
))
2211 status
= device_create_file(dev
, &dev_attr_suspend_standby_state
);
2214 status
= device_create_file(dev
, &dev_attr_suspend_mem_state
);
2217 status
= device_create_file(dev
, &dev_attr_suspend_disk_state
);
2221 if (ops
->set_suspend_voltage
) {
2222 status
= device_create_file(dev
,
2223 &dev_attr_suspend_standby_microvolts
);
2226 status
= device_create_file(dev
,
2227 &dev_attr_suspend_mem_microvolts
);
2230 status
= device_create_file(dev
,
2231 &dev_attr_suspend_disk_microvolts
);
2236 if (ops
->set_suspend_mode
) {
2237 status
= device_create_file(dev
,
2238 &dev_attr_suspend_standby_mode
);
2241 status
= device_create_file(dev
,
2242 &dev_attr_suspend_mem_mode
);
2245 status
= device_create_file(dev
,
2246 &dev_attr_suspend_disk_mode
);
2255 * regulator_register - register regulator
2256 * @regulator_desc: regulator to register
2257 * @dev: struct device for the regulator
2258 * @init_data: platform provided init data, passed through by driver
2259 * @driver_data: private regulator data
2261 * Called by regulator drivers to register a regulator.
2262 * Returns 0 on success.
2264 struct regulator_dev
*regulator_register(struct regulator_desc
*regulator_desc
,
2265 struct device
*dev
, struct regulator_init_data
*init_data
,
2268 static atomic_t regulator_no
= ATOMIC_INIT(0);
2269 struct regulator_dev
*rdev
;
2272 if (regulator_desc
== NULL
)
2273 return ERR_PTR(-EINVAL
);
2275 if (regulator_desc
->name
== NULL
|| regulator_desc
->ops
== NULL
)
2276 return ERR_PTR(-EINVAL
);
2278 if (regulator_desc
->type
!= REGULATOR_VOLTAGE
&&
2279 regulator_desc
->type
!= REGULATOR_CURRENT
)
2280 return ERR_PTR(-EINVAL
);
2283 return ERR_PTR(-EINVAL
);
2285 rdev
= kzalloc(sizeof(struct regulator_dev
), GFP_KERNEL
);
2287 return ERR_PTR(-ENOMEM
);
2289 mutex_lock(®ulator_list_mutex
);
2291 mutex_init(&rdev
->mutex
);
2292 rdev
->reg_data
= driver_data
;
2293 rdev
->owner
= regulator_desc
->owner
;
2294 rdev
->desc
= regulator_desc
;
2295 INIT_LIST_HEAD(&rdev
->consumer_list
);
2296 INIT_LIST_HEAD(&rdev
->supply_list
);
2297 INIT_LIST_HEAD(&rdev
->list
);
2298 INIT_LIST_HEAD(&rdev
->slist
);
2299 BLOCKING_INIT_NOTIFIER_HEAD(&rdev
->notifier
);
2301 /* preform any regulator specific init */
2302 if (init_data
->regulator_init
) {
2303 ret
= init_data
->regulator_init(rdev
->reg_data
);
2308 /* register with sysfs */
2309 rdev
->dev
.class = ®ulator_class
;
2310 rdev
->dev
.parent
= dev
;
2311 dev_set_name(&rdev
->dev
, "regulator.%d",
2312 atomic_inc_return(®ulator_no
) - 1);
2313 ret
= device_register(&rdev
->dev
);
2317 dev_set_drvdata(&rdev
->dev
, rdev
);
2319 /* set regulator constraints */
2320 ret
= set_machine_constraints(rdev
, &init_data
->constraints
);
2324 /* add attributes supported by this regulator */
2325 ret
= add_regulator_attributes(rdev
);
2329 /* set supply regulator if it exists */
2330 if (init_data
->supply_regulator_dev
) {
2331 ret
= set_supply(rdev
,
2332 dev_get_drvdata(init_data
->supply_regulator_dev
));
2337 /* add consumers devices */
2338 for (i
= 0; i
< init_data
->num_consumer_supplies
; i
++) {
2339 ret
= set_consumer_device_supply(rdev
,
2340 init_data
->consumer_supplies
[i
].dev
,
2341 init_data
->consumer_supplies
[i
].dev_name
,
2342 init_data
->consumer_supplies
[i
].supply
);
2344 for (--i
; i
>= 0; i
--)
2345 unset_consumer_device_supply(rdev
,
2346 init_data
->consumer_supplies
[i
].dev_name
,
2347 init_data
->consumer_supplies
[i
].dev
);
2352 list_add(&rdev
->list
, ®ulator_list
);
2354 mutex_unlock(®ulator_list_mutex
);
2358 device_unregister(&rdev
->dev
);
2359 /* device core frees rdev */
2360 rdev
= ERR_PTR(ret
);
2365 rdev
= ERR_PTR(ret
);
2368 EXPORT_SYMBOL_GPL(regulator_register
);
2371 * regulator_unregister - unregister regulator
2372 * @rdev: regulator to unregister
2374 * Called by regulator drivers to unregister a regulator.
2376 void regulator_unregister(struct regulator_dev
*rdev
)
2381 mutex_lock(®ulator_list_mutex
);
2382 WARN_ON(rdev
->open_count
);
2383 unset_regulator_supplies(rdev
);
2384 list_del(&rdev
->list
);
2386 sysfs_remove_link(&rdev
->dev
.kobj
, "supply");
2387 device_unregister(&rdev
->dev
);
2388 mutex_unlock(®ulator_list_mutex
);
2390 EXPORT_SYMBOL_GPL(regulator_unregister
);
2393 * regulator_suspend_prepare - prepare regulators for system wide suspend
2394 * @state: system suspend state
2396 * Configure each regulator with it's suspend operating parameters for state.
2397 * This will usually be called by machine suspend code prior to supending.
2399 int regulator_suspend_prepare(suspend_state_t state
)
2401 struct regulator_dev
*rdev
;
2404 /* ON is handled by regulator active state */
2405 if (state
== PM_SUSPEND_ON
)
2408 mutex_lock(®ulator_list_mutex
);
2409 list_for_each_entry(rdev
, ®ulator_list
, list
) {
2411 mutex_lock(&rdev
->mutex
);
2412 ret
= suspend_prepare(rdev
, state
);
2413 mutex_unlock(&rdev
->mutex
);
2416 printk(KERN_ERR
"%s: failed to prepare %s\n",
2417 __func__
, rdev_get_name(rdev
));
2422 mutex_unlock(®ulator_list_mutex
);
2425 EXPORT_SYMBOL_GPL(regulator_suspend_prepare
);
2428 * regulator_has_full_constraints - the system has fully specified constraints
2430 * Calling this function will cause the regulator API to disable all
2431 * regulators which have a zero use count and don't have an always_on
2432 * constraint in a late_initcall.
2434 * The intention is that this will become the default behaviour in a
2435 * future kernel release so users are encouraged to use this facility
2438 void regulator_has_full_constraints(void)
2440 has_full_constraints
= 1;
2442 EXPORT_SYMBOL_GPL(regulator_has_full_constraints
);
2445 * rdev_get_drvdata - get rdev regulator driver data
2448 * Get rdev regulator driver private data. This call can be used in the
2449 * regulator driver context.
2451 void *rdev_get_drvdata(struct regulator_dev
*rdev
)
2453 return rdev
->reg_data
;
2455 EXPORT_SYMBOL_GPL(rdev_get_drvdata
);
2458 * regulator_get_drvdata - get regulator driver data
2459 * @regulator: regulator
2461 * Get regulator driver private data. This call can be used in the consumer
2462 * driver context when non API regulator specific functions need to be called.
2464 void *regulator_get_drvdata(struct regulator
*regulator
)
2466 return regulator
->rdev
->reg_data
;
2468 EXPORT_SYMBOL_GPL(regulator_get_drvdata
);
2471 * regulator_set_drvdata - set regulator driver data
2472 * @regulator: regulator
2475 void regulator_set_drvdata(struct regulator
*regulator
, void *data
)
2477 regulator
->rdev
->reg_data
= data
;
2479 EXPORT_SYMBOL_GPL(regulator_set_drvdata
);
2482 * regulator_get_id - get regulator ID
2485 int rdev_get_id(struct regulator_dev
*rdev
)
2487 return rdev
->desc
->id
;
2489 EXPORT_SYMBOL_GPL(rdev_get_id
);
2491 struct device
*rdev_get_dev(struct regulator_dev
*rdev
)
2495 EXPORT_SYMBOL_GPL(rdev_get_dev
);
2497 void *regulator_get_init_drvdata(struct regulator_init_data
*reg_init_data
)
2499 return reg_init_data
->driver_data
;
2501 EXPORT_SYMBOL_GPL(regulator_get_init_drvdata
);
2503 static int __init
regulator_init(void)
2507 printk(KERN_INFO
"regulator: core version %s\n", REGULATOR_VERSION
);
2509 ret
= class_register(®ulator_class
);
2511 regulator_dummy_init();
2516 /* init early to allow our consumers to complete system booting */
2517 core_initcall(regulator_init
);
2519 static int __init
regulator_init_complete(void)
2521 struct regulator_dev
*rdev
;
2522 struct regulator_ops
*ops
;
2523 struct regulation_constraints
*c
;
2527 mutex_lock(®ulator_list_mutex
);
2529 /* If we have a full configuration then disable any regulators
2530 * which are not in use or always_on. This will become the
2531 * default behaviour in the future.
2533 list_for_each_entry(rdev
, ®ulator_list
, list
) {
2534 ops
= rdev
->desc
->ops
;
2535 c
= rdev
->constraints
;
2537 name
= rdev_get_name(rdev
);
2539 if (!ops
->disable
|| (c
&& c
->always_on
))
2542 mutex_lock(&rdev
->mutex
);
2544 if (rdev
->use_count
)
2547 /* If we can't read the status assume it's on. */
2548 if (ops
->is_enabled
)
2549 enabled
= ops
->is_enabled(rdev
);
2556 if (has_full_constraints
) {
2557 /* We log since this may kill the system if it
2559 printk(KERN_INFO
"%s: disabling %s\n",
2561 ret
= ops
->disable(rdev
);
2564 "%s: couldn't disable %s: %d\n",
2565 __func__
, name
, ret
);
2568 /* The intention is that in future we will
2569 * assume that full constraints are provided
2570 * so warn even if we aren't going to do
2574 "%s: incomplete constraints, leaving %s on\n",
2579 mutex_unlock(&rdev
->mutex
);
2582 mutex_unlock(®ulator_list_mutex
);
2586 late_initcall(regulator_init_complete
);