diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-03 13:39:20 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-03 13:39:20 -0400 |
commit | 18b34b9546dc192d978dda940673f40928d2e36e (patch) | |
tree | ca396840ed95fc46cd360c68bf2cefe5ab4cbda8 | |
parent | ca1ee219c070eab755712d50638bbcd1f8630fc1 (diff) | |
parent | d6bb69cfa88b8ac9f952de4fada5b216d5ba8830 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6: (32 commits)
regulator: twl4030 VAUX3 supports 3.0V
regulator: Support disabling of unused regulators by machines
regulator: Don't increment use_count for boot_on regulators
twl4030-regulator: expose VPLL2
regulator: refcount fixes
regulator: Don't warn if we failed to get a regulator
regulator: Allow boot_on regulators to be disabled by clients
regulator: Implement list_voltage for WM835x LDOs and DCDCs
twl4030-regulator: list more VAUX4 voltages
regulator: Don't warn on omitted voltage constraints
regulator: Implement list_voltage() for WM8400 DCDCs and LDOs
MMC: regulator utilities
regulator: twl4030 voltage enumeration (v2)
regulator: twl4030 regulators
regulator: get_status() grows kerneldoc
regulator: enumerate voltages (v2)
regulator: Fix get_mode() for WM835x DCDCs
regulator: Allow regulators to set the initial operating mode
regulator: Suggest use of datasheet supply or pin names for consumers
regulator: email - update email address and regulator webpage.
...
-rw-r--r-- | Documentation/ABI/testing/sysfs-class-regulator | 57 | ||||
-rw-r--r-- | MAINTAINERS | 2 | ||||
-rw-r--r-- | drivers/mfd/twl4030-core.c | 2 | ||||
-rw-r--r-- | drivers/mmc/core/core.c | 100 | ||||
-rw-r--r-- | drivers/regulator/Kconfig | 13 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 1 | ||||
-rw-r--r-- | drivers/regulator/bq24022.c | 3 | ||||
-rw-r--r-- | drivers/regulator/core.c | 386 | ||||
-rw-r--r-- | drivers/regulator/da903x.c | 3 | ||||
-rw-r--r-- | drivers/regulator/fixed.c | 3 | ||||
-rw-r--r-- | drivers/regulator/pcf50633-regulator.c | 3 | ||||
-rw-r--r-- | drivers/regulator/twl4030-regulator.c | 500 | ||||
-rw-r--r-- | drivers/regulator/virtual.c | 14 | ||||
-rw-r--r-- | drivers/regulator/wm8350-regulator.c | 57 | ||||
-rw-r--r-- | drivers/regulator/wm8400-regulator.c | 36 | ||||
-rw-r--r-- | include/linux/i2c/twl4030.h | 47 | ||||
-rw-r--r-- | include/linux/mmc/host.h | 5 | ||||
-rw-r--r-- | include/linux/regulator/bq24022.h | 3 | ||||
-rw-r--r-- | include/linux/regulator/consumer.h | 6 | ||||
-rw-r--r-- | include/linux/regulator/driver.h | 81 | ||||
-rw-r--r-- | include/linux/regulator/fixed.h | 3 | ||||
-rw-r--r-- | include/linux/regulator/machine.h | 12 |
22 files changed, 1220 insertions, 117 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-regulator b/Documentation/ABI/testing/sysfs-class-regulator index 873ef1fc1569..e091fa873792 100644 --- a/Documentation/ABI/testing/sysfs-class-regulator +++ b/Documentation/ABI/testing/sysfs-class-regulator | |||
@@ -4,8 +4,8 @@ KernelVersion: 2.6.26 | |||
4 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> | 4 | Contact: Liam Girdwood <lrg@slimlogic.co.uk> |
5 | Description: | 5 | Description: |
6 | Some regulator directories will contain a field called | 6 | Some regulator directories will contain a field called |
7 | state. This reports the regulator enable status, for | 7 | state. This reports the regulator enable control, for |
8 | regulators which can report that value. | 8 | regulators which can report that input value. |
9 | 9 | ||
10 | This will be one of the following strings: | 10 | This will be one of the following strings: |
11 | 11 | ||
@@ -14,16 +14,54 @@ Description: | |||
14 | 'unknown' | 14 | 'unknown' |
15 | 15 | ||
16 | 'enabled' means the regulator output is ON and is supplying | 16 | 'enabled' means the regulator output is ON and is supplying |
17 | power to the system. | 17 | power to the system (assuming no error prevents it). |
18 | 18 | ||
19 | 'disabled' means the regulator output is OFF and is not | 19 | 'disabled' means the regulator output is OFF and is not |
20 | supplying power to the system.. | 20 | supplying power to the system (unless some non-Linux |
21 | control has enabled it). | ||
21 | 22 | ||
22 | 'unknown' means software cannot determine the state, or | 23 | 'unknown' means software cannot determine the state, or |
23 | the reported state is invalid. | 24 | the reported state is invalid. |
24 | 25 | ||
25 | NOTE: this field can be used in conjunction with microvolts | 26 | NOTE: this field can be used in conjunction with microvolts |
26 | and microamps to determine regulator output levels. | 27 | or microamps to determine configured regulator output levels. |
28 | |||
29 | |||
30 | What: /sys/class/regulator/.../status | ||
31 | Description: | ||
32 | Some regulator directories will contain a field called | ||
33 | "status". This reports the current regulator status, for | ||
34 | regulators which can report that output value. | ||
35 | |||
36 | This will be one of the following strings: | ||
37 | |||
38 | off | ||
39 | on | ||
40 | error | ||
41 | fast | ||
42 | normal | ||
43 | idle | ||
44 | standby | ||
45 | |||
46 | "off" means the regulator is not supplying power to the | ||
47 | system. | ||
48 | |||
49 | "on" means the regulator is supplying power to the system, | ||
50 | and the regulator can't report a detailed operation mode. | ||
51 | |||
52 | "error" indicates an out-of-regulation status such as being | ||
53 | disabled due to thermal shutdown, or voltage being unstable | ||
54 | because of problems with the input power supply. | ||
55 | |||
56 | "fast", "normal", "idle", and "standby" are all detailed | ||
57 | regulator operation modes (described elsewhere). They | ||
58 | imply "on", but provide more detail. | ||
59 | |||
60 | Note that regulator status is a function of many inputs, | ||
61 | not limited to control inputs from Linux. For example, | ||
62 | the actual load presented may trigger "error" status; or | ||
63 | a regulator may be enabled by another user, even though | ||
64 | Linux did not enable it. | ||
27 | 65 | ||
28 | 66 | ||
29 | What: /sys/class/regulator/.../type | 67 | What: /sys/class/regulator/.../type |
@@ -58,7 +96,7 @@ Description: | |||
58 | Some regulator directories will contain a field called | 96 | Some regulator directories will contain a field called |
59 | microvolts. This holds the regulator output voltage setting | 97 | microvolts. This holds the regulator output voltage setting |
60 | measured in microvolts (i.e. E-6 Volts), for regulators | 98 | measured in microvolts (i.e. E-6 Volts), for regulators |
61 | which can report that voltage. | 99 | which can report the control input for voltage. |
62 | 100 | ||
63 | NOTE: This value should not be used to determine the regulator | 101 | NOTE: This value should not be used to determine the regulator |
64 | output voltage level as this value is the same regardless of | 102 | output voltage level as this value is the same regardless of |
@@ -73,7 +111,7 @@ Description: | |||
73 | Some regulator directories will contain a field called | 111 | Some regulator directories will contain a field called |
74 | microamps. This holds the regulator output current limit | 112 | microamps. This holds the regulator output current limit |
75 | setting measured in microamps (i.e. E-6 Amps), for regulators | 113 | setting measured in microamps (i.e. E-6 Amps), for regulators |
76 | which can report that current. | 114 | which can report the control input for a current limit. |
77 | 115 | ||
78 | NOTE: This value should not be used to determine the regulator | 116 | NOTE: This value should not be used to determine the regulator |
79 | output current level as this value is the same regardless of | 117 | output current level as this value is the same regardless of |
@@ -87,7 +125,7 @@ Contact: Liam Girdwood <lrg@slimlogic.co.uk> | |||
87 | Description: | 125 | Description: |
88 | Some regulator directories will contain a field called | 126 | Some regulator directories will contain a field called |
89 | opmode. This holds the current regulator operating mode, | 127 | opmode. This holds the current regulator operating mode, |
90 | for regulators which can report it. | 128 | for regulators which can report that control input value. |
91 | 129 | ||
92 | The opmode value can be one of the following strings: | 130 | The opmode value can be one of the following strings: |
93 | 131 | ||
@@ -101,7 +139,8 @@ Description: | |||
101 | 139 | ||
102 | NOTE: This value should not be used to determine the regulator | 140 | NOTE: This value should not be used to determine the regulator |
103 | output operating mode as this value is the same regardless of | 141 | output operating mode as this value is the same regardless of |
104 | whether the regulator is enabled or disabled. | 142 | whether the regulator is enabled or disabled. A "status" |
143 | attribute may be available to determine the actual mode. | ||
105 | 144 | ||
106 | 145 | ||
107 | What: /sys/class/regulator/.../min_microvolts | 146 | What: /sys/class/regulator/.../min_microvolts |
diff --git a/MAINTAINERS b/MAINTAINERS index 908226600f16..6fe6f39a3d31 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -4847,7 +4847,7 @@ M: lrg@slimlogic.co.uk | |||
4847 | P: Mark Brown | 4847 | P: Mark Brown |
4848 | M: broonie@opensource.wolfsonmicro.com | 4848 | M: broonie@opensource.wolfsonmicro.com |
4849 | W: http://opensource.wolfsonmicro.com/node/15 | 4849 | W: http://opensource.wolfsonmicro.com/node/15 |
4850 | W: http://www.slimlogic.co.uk/?page_id=5 | 4850 | W: http://www.slimlogic.co.uk/?p=48 |
4851 | T: git kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6.git | 4851 | T: git kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6.git |
4852 | S: Supported | 4852 | S: Supported |
4853 | 4853 | ||
diff --git a/drivers/mfd/twl4030-core.c b/drivers/mfd/twl4030-core.c index 68826f1e36bc..ec90e953adce 100644 --- a/drivers/mfd/twl4030-core.c +++ b/drivers/mfd/twl4030-core.c | |||
@@ -592,11 +592,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features) | |||
592 | 592 | ||
593 | /* maybe add LDOs that are omitted on cost-reduced parts */ | 593 | /* maybe add LDOs that are omitted on cost-reduced parts */ |
594 | if (twl_has_regulator() && !(features & TPS_SUBSET)) { | 594 | if (twl_has_regulator() && !(features & TPS_SUBSET)) { |
595 | /* | ||
596 | child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2); | 595 | child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2); |
597 | if (IS_ERR(child)) | 596 | if (IS_ERR(child)) |
598 | return PTR_ERR(child); | 597 | return PTR_ERR(child); |
599 | */ | ||
600 | 598 | ||
601 | child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2); | 599 | child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2); |
602 | if (IS_ERR(child)) | 600 | if (IS_ERR(child)) |
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index df6ce4a06cf3..1445ea8f10a6 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/leds.h> | 21 | #include <linux/leds.h> |
22 | #include <linux/scatterlist.h> | 22 | #include <linux/scatterlist.h> |
23 | #include <linux/log2.h> | 23 | #include <linux/log2.h> |
24 | #include <linux/regulator/consumer.h> | ||
24 | 25 | ||
25 | #include <linux/mmc/card.h> | 26 | #include <linux/mmc/card.h> |
26 | #include <linux/mmc/host.h> | 27 | #include <linux/mmc/host.h> |
@@ -523,6 +524,105 @@ u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max) | |||
523 | } | 524 | } |
524 | EXPORT_SYMBOL(mmc_vddrange_to_ocrmask); | 525 | EXPORT_SYMBOL(mmc_vddrange_to_ocrmask); |
525 | 526 | ||
527 | #ifdef CONFIG_REGULATOR | ||
528 | |||
529 | /** | ||
530 | * mmc_regulator_get_ocrmask - return mask of supported voltages | ||
531 | * @supply: regulator to use | ||
532 | * | ||
533 | * This returns either a negative errno, or a mask of voltages that | ||
534 | * can be provided to MMC/SD/SDIO devices using the specified voltage | ||
535 | * regulator. This would normally be called before registering the | ||
536 | * MMC host adapter. | ||
537 | */ | ||
538 | int mmc_regulator_get_ocrmask(struct regulator *supply) | ||
539 | { | ||
540 | int result = 0; | ||
541 | int count; | ||
542 | int i; | ||
543 | |||
544 | count = regulator_count_voltages(supply); | ||
545 | if (count < 0) | ||
546 | return count; | ||
547 | |||
548 | for (i = 0; i < count; i++) { | ||
549 | int vdd_uV; | ||
550 | int vdd_mV; | ||
551 | |||
552 | vdd_uV = regulator_list_voltage(supply, i); | ||
553 | if (vdd_uV <= 0) | ||
554 | continue; | ||
555 | |||
556 | vdd_mV = vdd_uV / 1000; | ||
557 | result |= mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV); | ||
558 | } | ||
559 | |||
560 | return result; | ||
561 | } | ||
562 | EXPORT_SYMBOL(mmc_regulator_get_ocrmask); | ||
563 | |||
564 | /** | ||
565 | * mmc_regulator_set_ocr - set regulator to match host->ios voltage | ||
566 | * @vdd_bit: zero for power off, else a bit number (host->ios.vdd) | ||
567 | * @supply: regulator to use | ||
568 | * | ||
569 | * Returns zero on success, else negative errno. | ||
570 | * | ||
571 | * MMC host drivers may use this to enable or disable a regulator using | ||
572 | * a particular supply voltage. This would normally be called from the | ||
573 | * set_ios() method. | ||
574 | */ | ||
575 | int mmc_regulator_set_ocr(struct regulator *supply, unsigned short vdd_bit) | ||
576 | { | ||
577 | int result = 0; | ||
578 | int min_uV, max_uV; | ||
579 | int enabled; | ||
580 | |||
581 | enabled = regulator_is_enabled(supply); | ||
582 | if (enabled < 0) | ||
583 | return enabled; | ||
584 | |||
585 | if (vdd_bit) { | ||
586 | int tmp; | ||
587 | int voltage; | ||
588 | |||
589 | /* REVISIT mmc_vddrange_to_ocrmask() may have set some | ||
590 | * bits this regulator doesn't quite support ... don't | ||
591 | * be too picky, most cards and regulators are OK with | ||
592 | * a 0.1V range goof (it's a small error percentage). | ||
593 | */ | ||
594 | tmp = vdd_bit - ilog2(MMC_VDD_165_195); | ||
595 | if (tmp == 0) { | ||
596 | min_uV = 1650 * 1000; | ||
597 | max_uV = 1950 * 1000; | ||
598 | } else { | ||
599 | min_uV = 1900 * 1000 + tmp * 100 * 1000; | ||
600 | max_uV = min_uV + 100 * 1000; | ||
601 | } | ||
602 | |||
603 | /* avoid needless changes to this voltage; the regulator | ||
604 | * might not allow this operation | ||
605 | */ | ||
606 | voltage = regulator_get_voltage(supply); | ||
607 | if (voltage < 0) | ||
608 | result = voltage; | ||
609 | else if (voltage < min_uV || voltage > max_uV) | ||
610 | result = regulator_set_voltage(supply, min_uV, max_uV); | ||
611 | else | ||
612 | result = 0; | ||
613 | |||
614 | if (result == 0 && !enabled) | ||
615 | result = regulator_enable(supply); | ||
616 | } else if (enabled) { | ||
617 | result = regulator_disable(supply); | ||
618 | } | ||
619 | |||
620 | return result; | ||
621 | } | ||
622 | EXPORT_SYMBOL(mmc_regulator_set_ocr); | ||
623 | |||
624 | #endif | ||
625 | |||
526 | /* | 626 | /* |
527 | * Mask off any voltages we don't support and select | 627 | * Mask off any voltages we don't support and select |
528 | * the lowest voltage | 628 | * the lowest voltage |
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index e7e0cf102d6d..e58c0ce65aa6 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -29,8 +29,12 @@ config REGULATOR_DEBUG | |||
29 | Say yes here to enable debugging support. | 29 | Say yes here to enable debugging support. |
30 | 30 | ||
31 | config REGULATOR_FIXED_VOLTAGE | 31 | config REGULATOR_FIXED_VOLTAGE |
32 | tristate | 32 | tristate "Fixed voltage regulator support" |
33 | default n | 33 | default n |
34 | help | ||
35 | This driver provides support for fixed voltage regulators, | ||
36 | useful for systems which use a combination of software | ||
37 | managed regulators and simple non-configurable regulators. | ||
34 | 38 | ||
35 | config REGULATOR_VIRTUAL_CONSUMER | 39 | config REGULATOR_VIRTUAL_CONSUMER |
36 | tristate "Virtual regulator consumer support" | 40 | tristate "Virtual regulator consumer support" |
@@ -52,6 +56,13 @@ config REGULATOR_BQ24022 | |||
52 | charging select between 100 mA and 500 mA charging current | 56 | charging select between 100 mA and 500 mA charging current |
53 | limit. | 57 | limit. |
54 | 58 | ||
59 | config REGULATOR_TWL4030 | ||
60 | bool "TI TWL4030/TWL5030/TPS695x0 PMIC" | ||
61 | depends on TWL4030_CORE | ||
62 | help | ||
63 | This driver supports the voltage regulators provided by | ||
64 | this family of companion chips. | ||
65 | |||
55 | config REGULATOR_WM8350 | 66 | config REGULATOR_WM8350 |
56 | tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC" | 67 | tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC" |
57 | depends on MFD_WM8350 | 68 | depends on MFD_WM8350 |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 61b30c6ddecc..bac133afc061 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -8,6 +8,7 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o | |||
8 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o | 8 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o |
9 | 9 | ||
10 | obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o | 10 | obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o |
11 | obj-$(CONFIG_REGULATOR_TWL4030) += twl4030-regulator.o | ||
11 | obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o | 12 | obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o |
12 | obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o | 13 | obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o |
13 | obj-$(CONFIG_REGULATOR_DA903X) += da903x.o | 14 | obj-$(CONFIG_REGULATOR_DA903X) += da903x.o |
diff --git a/drivers/regulator/bq24022.c b/drivers/regulator/bq24022.c index c175e38a4cd5..7ecb820ceebc 100644 --- a/drivers/regulator/bq24022.c +++ b/drivers/regulator/bq24022.c | |||
@@ -105,7 +105,8 @@ static int __init bq24022_probe(struct platform_device *pdev) | |||
105 | ret = gpio_direction_output(pdata->gpio_iset2, 0); | 105 | ret = gpio_direction_output(pdata->gpio_iset2, 0); |
106 | ret = gpio_direction_output(pdata->gpio_nce, 1); | 106 | ret = gpio_direction_output(pdata->gpio_nce, 1); |
107 | 107 | ||
108 | bq24022 = regulator_register(&bq24022_desc, &pdev->dev, pdata); | 108 | bq24022 = regulator_register(&bq24022_desc, &pdev->dev, |
109 | pdata->init_data, pdata); | ||
109 | if (IS_ERR(bq24022)) { | 110 | if (IS_ERR(bq24022)) { |
110 | dev_dbg(&pdev->dev, "couldn't register regulator\n"); | 111 | dev_dbg(&pdev->dev, "couldn't register regulator\n"); |
111 | ret = PTR_ERR(bq24022); | 112 | ret = PTR_ERR(bq24022); |
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index f511a406fcaa..01f7702a805d 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -28,33 +28,7 @@ | |||
28 | static DEFINE_MUTEX(regulator_list_mutex); | 28 | static DEFINE_MUTEX(regulator_list_mutex); |
29 | static LIST_HEAD(regulator_list); | 29 | static LIST_HEAD(regulator_list); |
30 | static LIST_HEAD(regulator_map_list); | 30 | static LIST_HEAD(regulator_map_list); |
31 | 31 | static int has_full_constraints; | |
32 | /* | ||
33 | * struct regulator_dev | ||
34 | * | ||
35 | * Voltage / Current regulator class device. One for each regulator. | ||
36 | */ | ||
37 | struct regulator_dev { | ||
38 | struct regulator_desc *desc; | ||
39 | int use_count; | ||
40 | |||
41 | /* lists we belong to */ | ||
42 | struct list_head list; /* list of all regulators */ | ||
43 | struct list_head slist; /* list of supplied regulators */ | ||
44 | |||
45 | /* lists we own */ | ||
46 | struct list_head consumer_list; /* consumers we supply */ | ||
47 | struct list_head supply_list; /* regulators we supply */ | ||
48 | |||
49 | struct blocking_notifier_head notifier; | ||
50 | struct mutex mutex; /* consumer lock */ | ||
51 | struct module *owner; | ||
52 | struct device dev; | ||
53 | struct regulation_constraints *constraints; | ||
54 | struct regulator_dev *supply; /* for tree */ | ||
55 | |||
56 | void *reg_data; /* regulator_dev data */ | ||
57 | }; | ||
58 | 32 | ||
59 | /* | 33 | /* |
60 | * struct regulator_map | 34 | * struct regulator_map |
@@ -79,7 +53,6 @@ struct regulator { | |||
79 | int uA_load; | 53 | int uA_load; |
80 | int min_uV; | 54 | int min_uV; |
81 | int max_uV; | 55 | int max_uV; |
82 | int enabled; /* count of client enables */ | ||
83 | char *supply_name; | 56 | char *supply_name; |
84 | struct device_attribute dev_attr; | 57 | struct device_attribute dev_attr; |
85 | struct regulator_dev *rdev; | 58 | struct regulator_dev *rdev; |
@@ -312,6 +285,47 @@ static ssize_t regulator_state_show(struct device *dev, | |||
312 | } | 285 | } |
313 | static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); | 286 | static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); |
314 | 287 | ||
288 | static ssize_t regulator_status_show(struct device *dev, | ||
289 | struct device_attribute *attr, char *buf) | ||
290 | { | ||
291 | struct regulator_dev *rdev = dev_get_drvdata(dev); | ||
292 | int status; | ||
293 | char *label; | ||
294 | |||
295 | status = rdev->desc->ops->get_status(rdev); | ||
296 | if (status < 0) | ||
297 | return status; | ||
298 | |||
299 | switch (status) { | ||
300 | case REGULATOR_STATUS_OFF: | ||
301 | label = "off"; | ||
302 | break; | ||
303 | case REGULATOR_STATUS_ON: | ||
304 | label = "on"; | ||
305 | break; | ||
306 | case REGULATOR_STATUS_ERROR: | ||
307 | label = "error"; | ||
308 | break; | ||
309 | case REGULATOR_STATUS_FAST: | ||
310 | label = "fast"; | ||
311 | break; | ||
312 | case REGULATOR_STATUS_NORMAL: | ||
313 | label = "normal"; | ||
314 | break; | ||
315 | case REGULATOR_STATUS_IDLE: | ||
316 | label = "idle"; | ||
317 | break; | ||
318 | case REGULATOR_STATUS_STANDBY: | ||
319 | label = "standby"; | ||
320 | break; | ||
321 | default: | ||
322 | return -ERANGE; | ||
323 | } | ||
324 | |||
325 | return sprintf(buf, "%s\n", label); | ||
326 | } | ||
327 | static DEVICE_ATTR(status, 0444, regulator_status_show, NULL); | ||
328 | |||
315 | static ssize_t regulator_min_uA_show(struct device *dev, | 329 | static ssize_t regulator_min_uA_show(struct device *dev, |
316 | struct device_attribute *attr, char *buf) | 330 | struct device_attribute *attr, char *buf) |
317 | { | 331 | { |
@@ -678,6 +692,73 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
678 | else | 692 | else |
679 | name = "regulator"; | 693 | name = "regulator"; |
680 | 694 | ||
695 | /* constrain machine-level voltage specs to fit | ||
696 | * the actual range supported by this regulator. | ||
697 | */ | ||
698 | if (ops->list_voltage && rdev->desc->n_voltages) { | ||
699 | int count = rdev->desc->n_voltages; | ||
700 | int i; | ||
701 | int min_uV = INT_MAX; | ||
702 | int max_uV = INT_MIN; | ||
703 | int cmin = constraints->min_uV; | ||
704 | int cmax = constraints->max_uV; | ||
705 | |||
706 | /* it's safe to autoconfigure fixed-voltage supplies */ | ||
707 | if (count == 1 && !cmin) { | ||
708 | cmin = INT_MIN; | ||
709 | cmax = INT_MAX; | ||
710 | } | ||
711 | |||
712 | /* voltage constraints are optional */ | ||
713 | if ((cmin == 0) && (cmax == 0)) | ||
714 | goto out; | ||
715 | |||
716 | /* else require explicit machine-level constraints */ | ||
717 | if (cmin <= 0 || cmax <= 0 || cmax < cmin) { | ||
718 | pr_err("%s: %s '%s' voltage constraints\n", | ||
719 | __func__, "invalid", name); | ||
720 | ret = -EINVAL; | ||
721 | goto out; | ||
722 | } | ||
723 | |||
724 | /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ | ||
725 | for (i = 0; i < count; i++) { | ||
726 | int value; | ||
727 | |||
728 | value = ops->list_voltage(rdev, i); | ||
729 | if (value <= 0) | ||
730 | continue; | ||
731 | |||
732 | /* maybe adjust [min_uV..max_uV] */ | ||
733 | if (value >= cmin && value < min_uV) | ||
734 | min_uV = value; | ||
735 | if (value <= cmax && value > max_uV) | ||
736 | max_uV = value; | ||
737 | } | ||
738 | |||
739 | /* final: [min_uV..max_uV] valid iff constraints valid */ | ||
740 | if (max_uV < min_uV) { | ||
741 | pr_err("%s: %s '%s' voltage constraints\n", | ||
742 | __func__, "unsupportable", name); | ||
743 | ret = -EINVAL; | ||
744 | goto out; | ||
745 | } | ||
746 | |||
747 | /* use regulator's subset of machine constraints */ | ||
748 | if (constraints->min_uV < min_uV) { | ||
749 | pr_debug("%s: override '%s' %s, %d -> %d\n", | ||
750 | __func__, name, "min_uV", | ||
751 | constraints->min_uV, min_uV); | ||
752 | constraints->min_uV = min_uV; | ||
753 | } | ||
754 | if (constraints->max_uV > max_uV) { | ||
755 | pr_debug("%s: override '%s' %s, %d -> %d\n", | ||
756 | __func__, name, "max_uV", | ||
757 | constraints->max_uV, max_uV); | ||
758 | constraints->max_uV = max_uV; | ||
759 | } | ||
760 | } | ||
761 | |||
681 | rdev->constraints = constraints; | 762 | rdev->constraints = constraints; |
682 | 763 | ||
683 | /* do we need to apply the constraint voltage */ | 764 | /* do we need to apply the constraint voltage */ |
@@ -695,10 +776,6 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
695 | } | 776 | } |
696 | } | 777 | } |
697 | 778 | ||
698 | /* are we enabled at boot time by firmware / bootloader */ | ||
699 | if (rdev->constraints->boot_on) | ||
700 | rdev->use_count = 1; | ||
701 | |||
702 | /* do we need to setup our suspend state */ | 779 | /* do we need to setup our suspend state */ |
703 | if (constraints->initial_state) { | 780 | if (constraints->initial_state) { |
704 | ret = suspend_prepare(rdev, constraints->initial_state); | 781 | ret = suspend_prepare(rdev, constraints->initial_state); |
@@ -710,11 +787,27 @@ static int set_machine_constraints(struct regulator_dev *rdev, | |||
710 | } | 787 | } |
711 | } | 788 | } |
712 | 789 | ||
713 | /* if always_on is set then turn the regulator on if it's not | 790 | if (constraints->initial_mode) { |
714 | * already on. */ | 791 | if (!ops->set_mode) { |
715 | if (constraints->always_on && ops->enable && | 792 | printk(KERN_ERR "%s: no set_mode operation for %s\n", |
716 | ((ops->is_enabled && !ops->is_enabled(rdev)) || | 793 | __func__, name); |
717 | (!ops->is_enabled && !constraints->boot_on))) { | 794 | ret = -EINVAL; |
795 | goto out; | ||
796 | } | ||
797 | |||
798 | ret = ops->set_mode(rdev, constraints->initial_mode); | ||
799 | if (ret < 0) { | ||
800 | printk(KERN_ERR | ||
801 | "%s: failed to set initial mode for %s: %d\n", | ||
802 | __func__, name, ret); | ||
803 | goto out; | ||
804 | } | ||
805 | } | ||
806 | |||
807 | /* If the constraints say the regulator should be on at this point | ||
808 | * and we have control then make sure it is enabled. | ||
809 | */ | ||
810 | if ((constraints->always_on || constraints->boot_on) && ops->enable) { | ||
718 | ret = ops->enable(rdev); | 811 | ret = ops->enable(rdev); |
719 | if (ret < 0) { | 812 | if (ret < 0) { |
720 | printk(KERN_ERR "%s: failed to enable %s\n", | 813 | printk(KERN_ERR "%s: failed to enable %s\n", |
@@ -817,6 +910,19 @@ static void unset_consumer_device_supply(struct regulator_dev *rdev, | |||
817 | } | 910 | } |
818 | } | 911 | } |
819 | 912 | ||
913 | static void unset_regulator_supplies(struct regulator_dev *rdev) | ||
914 | { | ||
915 | struct regulator_map *node, *n; | ||
916 | |||
917 | list_for_each_entry_safe(node, n, ®ulator_map_list, list) { | ||
918 | if (rdev == node->regulator) { | ||
919 | list_del(&node->list); | ||
920 | kfree(node); | ||
921 | return; | ||
922 | } | ||
923 | } | ||
924 | } | ||
925 | |||
820 | #define REG_STR_SIZE 32 | 926 | #define REG_STR_SIZE 32 |
821 | 927 | ||
822 | static struct regulator *create_regulator(struct regulator_dev *rdev, | 928 | static struct regulator *create_regulator(struct regulator_dev *rdev, |
@@ -898,9 +1004,12 @@ overflow_err: | |||
898 | * @id: Supply name or regulator ID. | 1004 | * @id: Supply name or regulator ID. |
899 | * | 1005 | * |
900 | * Returns a struct regulator corresponding to the regulator producer, | 1006 | * Returns a struct regulator corresponding to the regulator producer, |
901 | * or IS_ERR() condition containing errno. Use of supply names | 1007 | * or IS_ERR() condition containing errno. |
902 | * configured via regulator_set_device_supply() is strongly | 1008 | * |
903 | * encouraged. | 1009 | * Use of supply names configured via regulator_set_device_supply() is |
1010 | * strongly encouraged. It is recommended that the supply name used | ||
1011 | * should match the name used for the supply and/or the relevant | ||
1012 | * device pins in the datasheet. | ||
904 | */ | 1013 | */ |
905 | struct regulator *regulator_get(struct device *dev, const char *id) | 1014 | struct regulator *regulator_get(struct device *dev, const char *id) |
906 | { | 1015 | { |
@@ -922,8 +1031,6 @@ struct regulator *regulator_get(struct device *dev, const char *id) | |||
922 | goto found; | 1031 | goto found; |
923 | } | 1032 | } |
924 | } | 1033 | } |
925 | printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", | ||
926 | id); | ||
927 | mutex_unlock(®ulator_list_mutex); | 1034 | mutex_unlock(®ulator_list_mutex); |
928 | return regulator; | 1035 | return regulator; |
929 | 1036 | ||
@@ -961,10 +1068,6 @@ void regulator_put(struct regulator *regulator) | |||
961 | mutex_lock(®ulator_list_mutex); | 1068 | mutex_lock(®ulator_list_mutex); |
962 | rdev = regulator->rdev; | 1069 | rdev = regulator->rdev; |
963 | 1070 | ||
964 | if (WARN(regulator->enabled, "Releasing supply %s while enabled\n", | ||
965 | regulator->supply_name)) | ||
966 | _regulator_disable(rdev); | ||
967 | |||
968 | /* remove any sysfs entries */ | 1071 | /* remove any sysfs entries */ |
969 | if (regulator->dev) { | 1072 | if (regulator->dev) { |
970 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); | 1073 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); |
@@ -1039,12 +1142,7 @@ int regulator_enable(struct regulator *regulator) | |||
1039 | int ret = 0; | 1142 | int ret = 0; |
1040 | 1143 | ||
1041 | mutex_lock(&rdev->mutex); | 1144 | mutex_lock(&rdev->mutex); |
1042 | if (regulator->enabled == 0) | 1145 | ret = _regulator_enable(rdev); |
1043 | ret = _regulator_enable(rdev); | ||
1044 | else if (regulator->enabled < 0) | ||
1045 | ret = -EIO; | ||
1046 | if (ret == 0) | ||
1047 | regulator->enabled++; | ||
1048 | mutex_unlock(&rdev->mutex); | 1146 | mutex_unlock(&rdev->mutex); |
1049 | return ret; | 1147 | return ret; |
1050 | } | 1148 | } |
@@ -1055,6 +1153,11 @@ static int _regulator_disable(struct regulator_dev *rdev) | |||
1055 | { | 1153 | { |
1056 | int ret = 0; | 1154 | int ret = 0; |
1057 | 1155 | ||
1156 | if (WARN(rdev->use_count <= 0, | ||
1157 | "unbalanced disables for %s\n", | ||
1158 | rdev->desc->name)) | ||
1159 | return -EIO; | ||
1160 | |||
1058 | /* are we the last user and permitted to disable ? */ | 1161 | /* are we the last user and permitted to disable ? */ |
1059 | if (rdev->use_count == 1 && !rdev->constraints->always_on) { | 1162 | if (rdev->use_count == 1 && !rdev->constraints->always_on) { |
1060 | 1163 | ||
@@ -1103,16 +1206,7 @@ int regulator_disable(struct regulator *regulator) | |||
1103 | int ret = 0; | 1206 | int ret = 0; |
1104 | 1207 | ||
1105 | mutex_lock(&rdev->mutex); | 1208 | mutex_lock(&rdev->mutex); |
1106 | if (regulator->enabled == 1) { | 1209 | ret = _regulator_disable(rdev); |
1107 | ret = _regulator_disable(rdev); | ||
1108 | if (ret == 0) | ||
1109 | regulator->uA_load = 0; | ||
1110 | } else if (WARN(regulator->enabled <= 0, | ||
1111 | "unbalanced disables for supply %s\n", | ||
1112 | regulator->supply_name)) | ||
1113 | ret = -EIO; | ||
1114 | if (ret == 0) | ||
1115 | regulator->enabled--; | ||
1116 | mutex_unlock(&rdev->mutex); | 1210 | mutex_unlock(&rdev->mutex); |
1117 | return ret; | 1211 | return ret; |
1118 | } | 1212 | } |
@@ -1159,7 +1253,6 @@ int regulator_force_disable(struct regulator *regulator) | |||
1159 | int ret; | 1253 | int ret; |
1160 | 1254 | ||
1161 | mutex_lock(®ulator->rdev->mutex); | 1255 | mutex_lock(®ulator->rdev->mutex); |
1162 | regulator->enabled = 0; | ||
1163 | regulator->uA_load = 0; | 1256 | regulator->uA_load = 0; |
1164 | ret = _regulator_force_disable(regulator->rdev); | 1257 | ret = _regulator_force_disable(regulator->rdev); |
1165 | mutex_unlock(®ulator->rdev->mutex); | 1258 | mutex_unlock(®ulator->rdev->mutex); |
@@ -1204,6 +1297,56 @@ int regulator_is_enabled(struct regulator *regulator) | |||
1204 | EXPORT_SYMBOL_GPL(regulator_is_enabled); | 1297 | EXPORT_SYMBOL_GPL(regulator_is_enabled); |
1205 | 1298 | ||
1206 | /** | 1299 | /** |
1300 | * regulator_count_voltages - count regulator_list_voltage() selectors | ||
1301 | * @regulator: regulator source | ||
1302 | * | ||
1303 | * Returns number of selectors, or negative errno. Selectors are | ||
1304 | * numbered starting at zero, and typically correspond to bitfields | ||
1305 | * in hardware registers. | ||
1306 | */ | ||
1307 | int regulator_count_voltages(struct regulator *regulator) | ||
1308 | { | ||
1309 | struct regulator_dev *rdev = regulator->rdev; | ||
1310 | |||
1311 | return rdev->desc->n_voltages ? : -EINVAL; | ||
1312 | } | ||
1313 | EXPORT_SYMBOL_GPL(regulator_count_voltages); | ||
1314 | |||
1315 | /** | ||
1316 | * regulator_list_voltage - enumerate supported voltages | ||
1317 | * @regulator: regulator source | ||
1318 | * @selector: identify voltage to list | ||
1319 | * Context: can sleep | ||
1320 | * | ||
1321 | * Returns a voltage that can be passed to @regulator_set_voltage(), | ||
1322 | * zero if this selector code can't be used on this sytem, or a | ||
1323 | * negative errno. | ||
1324 | */ | ||
1325 | int regulator_list_voltage(struct regulator *regulator, unsigned selector) | ||
1326 | { | ||
1327 | struct regulator_dev *rdev = regulator->rdev; | ||
1328 | struct regulator_ops *ops = rdev->desc->ops; | ||
1329 | int ret; | ||
1330 | |||
1331 | if (!ops->list_voltage || selector >= rdev->desc->n_voltages) | ||
1332 | return -EINVAL; | ||
1333 | |||
1334 | mutex_lock(&rdev->mutex); | ||
1335 | ret = ops->list_voltage(rdev, selector); | ||
1336 | mutex_unlock(&rdev->mutex); | ||
1337 | |||
1338 | if (ret > 0) { | ||
1339 | if (ret < rdev->constraints->min_uV) | ||
1340 | ret = 0; | ||
1341 | else if (ret > rdev->constraints->max_uV) | ||
1342 | ret = 0; | ||
1343 | } | ||
1344 | |||
1345 | return ret; | ||
1346 | } | ||
1347 | EXPORT_SYMBOL_GPL(regulator_list_voltage); | ||
1348 | |||
1349 | /** | ||
1207 | * regulator_set_voltage - set regulator output voltage | 1350 | * regulator_set_voltage - set regulator output voltage |
1208 | * @regulator: regulator source | 1351 | * @regulator: regulator source |
1209 | * @min_uV: Minimum required voltage in uV | 1352 | * @min_uV: Minimum required voltage in uV |
@@ -1243,6 +1386,7 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | |||
1243 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); | 1386 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); |
1244 | 1387 | ||
1245 | out: | 1388 | out: |
1389 | _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL); | ||
1246 | mutex_unlock(&rdev->mutex); | 1390 | mutex_unlock(&rdev->mutex); |
1247 | return ret; | 1391 | return ret; |
1248 | } | 1392 | } |
@@ -1543,20 +1687,23 @@ int regulator_unregister_notifier(struct regulator *regulator, | |||
1543 | } | 1687 | } |
1544 | EXPORT_SYMBOL_GPL(regulator_unregister_notifier); | 1688 | EXPORT_SYMBOL_GPL(regulator_unregister_notifier); |
1545 | 1689 | ||
1546 | /* notify regulator consumers and downstream regulator consumers */ | 1690 | /* notify regulator consumers and downstream regulator consumers. |
1691 | * Note mutex must be held by caller. | ||
1692 | */ | ||
1547 | static void _notifier_call_chain(struct regulator_dev *rdev, | 1693 | static void _notifier_call_chain(struct regulator_dev *rdev, |
1548 | unsigned long event, void *data) | 1694 | unsigned long event, void *data) |
1549 | { | 1695 | { |
1550 | struct regulator_dev *_rdev; | 1696 | struct regulator_dev *_rdev; |
1551 | 1697 | ||
1552 | /* call rdev chain first */ | 1698 | /* call rdev chain first */ |
1553 | mutex_lock(&rdev->mutex); | ||
1554 | blocking_notifier_call_chain(&rdev->notifier, event, NULL); | 1699 | blocking_notifier_call_chain(&rdev->notifier, event, NULL); |
1555 | mutex_unlock(&rdev->mutex); | ||
1556 | 1700 | ||
1557 | /* now notify regulator we supply */ | 1701 | /* now notify regulator we supply */ |
1558 | list_for_each_entry(_rdev, &rdev->supply_list, slist) | 1702 | list_for_each_entry(_rdev, &rdev->supply_list, slist) { |
1559 | _notifier_call_chain(_rdev, event, data); | 1703 | mutex_lock(&_rdev->mutex); |
1704 | _notifier_call_chain(_rdev, event, data); | ||
1705 | mutex_unlock(&_rdev->mutex); | ||
1706 | } | ||
1560 | } | 1707 | } |
1561 | 1708 | ||
1562 | /** | 1709 | /** |
@@ -1703,6 +1850,7 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free); | |||
1703 | * | 1850 | * |
1704 | * Called by regulator drivers to notify clients a regulator event has | 1851 | * Called by regulator drivers to notify clients a regulator event has |
1705 | * occurred. We also notify regulator clients downstream. | 1852 | * occurred. We also notify regulator clients downstream. |
1853 | * Note lock must be held by caller. | ||
1706 | */ | 1854 | */ |
1707 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | 1855 | int regulator_notifier_call_chain(struct regulator_dev *rdev, |
1708 | unsigned long event, void *data) | 1856 | unsigned long event, void *data) |
@@ -1744,6 +1892,11 @@ static int add_regulator_attributes(struct regulator_dev *rdev) | |||
1744 | if (status < 0) | 1892 | if (status < 0) |
1745 | return status; | 1893 | return status; |
1746 | } | 1894 | } |
1895 | if (ops->get_status) { | ||
1896 | status = device_create_file(dev, &dev_attr_status); | ||
1897 | if (status < 0) | ||
1898 | return status; | ||
1899 | } | ||
1747 | 1900 | ||
1748 | /* some attributes are type-specific */ | 1901 | /* some attributes are type-specific */ |
1749 | if (rdev->desc->type == REGULATOR_CURRENT) { | 1902 | if (rdev->desc->type == REGULATOR_CURRENT) { |
@@ -1828,17 +1981,18 @@ static int add_regulator_attributes(struct regulator_dev *rdev) | |||
1828 | * regulator_register - register regulator | 1981 | * regulator_register - register regulator |
1829 | * @regulator_desc: regulator to register | 1982 | * @regulator_desc: regulator to register |
1830 | * @dev: struct device for the regulator | 1983 | * @dev: struct device for the regulator |
1984 | * @init_data: platform provided init data, passed through by driver | ||
1831 | * @driver_data: private regulator data | 1985 | * @driver_data: private regulator data |
1832 | * | 1986 | * |
1833 | * Called by regulator drivers to register a regulator. | 1987 | * Called by regulator drivers to register a regulator. |
1834 | * Returns 0 on success. | 1988 | * Returns 0 on success. |
1835 | */ | 1989 | */ |
1836 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | 1990 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, |
1837 | struct device *dev, void *driver_data) | 1991 | struct device *dev, struct regulator_init_data *init_data, |
1992 | void *driver_data) | ||
1838 | { | 1993 | { |
1839 | static atomic_t regulator_no = ATOMIC_INIT(0); | 1994 | static atomic_t regulator_no = ATOMIC_INIT(0); |
1840 | struct regulator_dev *rdev; | 1995 | struct regulator_dev *rdev; |
1841 | struct regulator_init_data *init_data = dev->platform_data; | ||
1842 | int ret, i; | 1996 | int ret, i; |
1843 | 1997 | ||
1844 | if (regulator_desc == NULL) | 1998 | if (regulator_desc == NULL) |
@@ -1945,6 +2099,7 @@ void regulator_unregister(struct regulator_dev *rdev) | |||
1945 | return; | 2099 | return; |
1946 | 2100 | ||
1947 | mutex_lock(®ulator_list_mutex); | 2101 | mutex_lock(®ulator_list_mutex); |
2102 | unset_regulator_supplies(rdev); | ||
1948 | list_del(&rdev->list); | 2103 | list_del(&rdev->list); |
1949 | if (rdev->supply) | 2104 | if (rdev->supply) |
1950 | sysfs_remove_link(&rdev->dev.kobj, "supply"); | 2105 | sysfs_remove_link(&rdev->dev.kobj, "supply"); |
@@ -1989,6 +2144,23 @@ out: | |||
1989 | EXPORT_SYMBOL_GPL(regulator_suspend_prepare); | 2144 | EXPORT_SYMBOL_GPL(regulator_suspend_prepare); |
1990 | 2145 | ||
1991 | /** | 2146 | /** |
2147 | * regulator_has_full_constraints - the system has fully specified constraints | ||
2148 | * | ||
2149 | * Calling this function will cause the regulator API to disable all | ||
2150 | * regulators which have a zero use count and don't have an always_on | ||
2151 | * constraint in a late_initcall. | ||
2152 | * | ||
2153 | * The intention is that this will become the default behaviour in a | ||
2154 | * future kernel release so users are encouraged to use this facility | ||
2155 | * now. | ||
2156 | */ | ||
2157 | void regulator_has_full_constraints(void) | ||
2158 | { | ||
2159 | has_full_constraints = 1; | ||
2160 | } | ||
2161 | EXPORT_SYMBOL_GPL(regulator_has_full_constraints); | ||
2162 | |||
2163 | /** | ||
1992 | * rdev_get_drvdata - get rdev regulator driver data | 2164 | * rdev_get_drvdata - get rdev regulator driver data |
1993 | * @rdev: regulator | 2165 | * @rdev: regulator |
1994 | * | 2166 | * |
@@ -2055,3 +2227,77 @@ static int __init regulator_init(void) | |||
2055 | 2227 | ||
2056 | /* init early to allow our consumers to complete system booting */ | 2228 | /* init early to allow our consumers to complete system booting */ |
2057 | core_initcall(regulator_init); | 2229 | core_initcall(regulator_init); |
2230 | |||
2231 | static int __init regulator_init_complete(void) | ||
2232 | { | ||
2233 | struct regulator_dev *rdev; | ||
2234 | struct regulator_ops *ops; | ||
2235 | struct regulation_constraints *c; | ||
2236 | int enabled, ret; | ||
2237 | const char *name; | ||
2238 | |||
2239 | mutex_lock(®ulator_list_mutex); | ||
2240 | |||
2241 | /* If we have a full configuration then disable any regulators | ||
2242 | * which are not in use or always_on. This will become the | ||
2243 | * default behaviour in the future. | ||
2244 | */ | ||
2245 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
2246 | ops = rdev->desc->ops; | ||
2247 | c = rdev->constraints; | ||
2248 | |||
2249 | if (c->name) | ||
2250 | name = c->name; | ||
2251 | else if (rdev->desc->name) | ||
2252 | name = rdev->desc->name; | ||
2253 | else | ||
2254 | name = "regulator"; | ||
2255 | |||
2256 | if (!ops->disable || c->always_on) | ||
2257 | continue; | ||
2258 | |||
2259 | mutex_lock(&rdev->mutex); | ||
2260 | |||
2261 | if (rdev->use_count) | ||
2262 | goto unlock; | ||
2263 | |||
2264 | /* If we can't read the status assume it's on. */ | ||
2265 | if (ops->is_enabled) | ||
2266 | enabled = ops->is_enabled(rdev); | ||
2267 | else | ||
2268 | enabled = 1; | ||
2269 | |||
2270 | if (!enabled) | ||
2271 | goto unlock; | ||
2272 | |||
2273 | if (has_full_constraints) { | ||
2274 | /* We log since this may kill the system if it | ||
2275 | * goes wrong. */ | ||
2276 | printk(KERN_INFO "%s: disabling %s\n", | ||
2277 | __func__, name); | ||
2278 | ret = ops->disable(rdev); | ||
2279 | if (ret != 0) { | ||
2280 | printk(KERN_ERR | ||
2281 | "%s: couldn't disable %s: %d\n", | ||
2282 | __func__, name, ret); | ||
2283 | } | ||
2284 | } else { | ||
2285 | /* The intention is that in future we will | ||
2286 | * assume that full constraints are provided | ||
2287 | * so warn even if we aren't going to do | ||
2288 | * anything here. | ||
2289 | */ | ||
2290 | printk(KERN_WARNING | ||
2291 | "%s: incomplete constraints, leaving %s on\n", | ||
2292 | __func__, name); | ||
2293 | } | ||
2294 | |||
2295 | unlock: | ||
2296 | mutex_unlock(&rdev->mutex); | ||
2297 | } | ||
2298 | |||
2299 | mutex_unlock(®ulator_list_mutex); | ||
2300 | |||
2301 | return 0; | ||
2302 | } | ||
2303 | late_initcall(regulator_init_complete); | ||
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c index fe77730a7edb..72b15495183c 100644 --- a/drivers/regulator/da903x.c +++ b/drivers/regulator/da903x.c | |||
@@ -471,7 +471,8 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev) | |||
471 | if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15) | 471 | if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15) |
472 | ri->desc.ops = &da9030_regulator_ldo1_15_ops; | 472 | ri->desc.ops = &da9030_regulator_ldo1_15_ops; |
473 | 473 | ||
474 | rdev = regulator_register(&ri->desc, &pdev->dev, ri); | 474 | rdev = regulator_register(&ri->desc, &pdev->dev, |
475 | pdev->dev.platform_data, ri); | ||
475 | if (IS_ERR(rdev)) { | 476 | if (IS_ERR(rdev)) { |
476 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 477 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
477 | ri->desc.name); | 478 | ri->desc.name); |
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index d31db3e14913..23d554628a76 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c | |||
@@ -73,7 +73,8 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev) | |||
73 | 73 | ||
74 | drvdata->microvolts = config->microvolts; | 74 | drvdata->microvolts = config->microvolts; |
75 | 75 | ||
76 | drvdata->dev = regulator_register(&drvdata->desc, drvdata); | 76 | drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, |
77 | config->init_data, drvdata); | ||
77 | if (IS_ERR(drvdata->dev)) { | 78 | if (IS_ERR(drvdata->dev)) { |
78 | ret = PTR_ERR(drvdata->dev); | 79 | ret = PTR_ERR(drvdata->dev); |
79 | goto err_name; | 80 | goto err_name; |
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c index 4cc85ec6e120..cd761d85c8fd 100644 --- a/drivers/regulator/pcf50633-regulator.c +++ b/drivers/regulator/pcf50633-regulator.c | |||
@@ -284,7 +284,8 @@ static int __devinit pcf50633_regulator_probe(struct platform_device *pdev) | |||
284 | /* Already set by core driver */ | 284 | /* Already set by core driver */ |
285 | pcf = platform_get_drvdata(pdev); | 285 | pcf = platform_get_drvdata(pdev); |
286 | 286 | ||
287 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, pcf); | 287 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, |
288 | pdev->dev.platform_data, pcf); | ||
288 | if (IS_ERR(rdev)) | 289 | if (IS_ERR(rdev)) |
289 | return PTR_ERR(rdev); | 290 | return PTR_ERR(rdev); |
290 | 291 | ||
diff --git a/drivers/regulator/twl4030-regulator.c b/drivers/regulator/twl4030-regulator.c new file mode 100644 index 000000000000..e2032fb60b55 --- /dev/null +++ b/drivers/regulator/twl4030-regulator.c | |||
@@ -0,0 +1,500 @@ | |||
1 | /* | ||
2 | * twl4030-regulator.c -- support regulators in twl4030 family chips | ||
3 | * | ||
4 | * Copyright (C) 2008 David Brownell | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/regulator/driver.h> | ||
17 | #include <linux/regulator/machine.h> | ||
18 | #include <linux/i2c/twl4030.h> | ||
19 | |||
20 | |||
21 | /* | ||
22 | * The TWL4030/TW5030/TPS659x0 family chips include power management, a | ||
23 | * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions | ||
24 | * include an audio codec, battery charger, and more voltage regulators. | ||
25 | * These chips are often used in OMAP-based systems. | ||
26 | * | ||
27 | * This driver implements software-based resource control for various | ||
28 | * voltage regulators. This is usually augmented with state machine | ||
29 | * based control. | ||
30 | */ | ||
31 | |||
32 | struct twlreg_info { | ||
33 | /* start of regulator's PM_RECEIVER control register bank */ | ||
34 | u8 base; | ||
35 | |||
36 | /* twl4030 resource ID, for resource control state machine */ | ||
37 | u8 id; | ||
38 | |||
39 | /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ | ||
40 | u8 table_len; | ||
41 | const u16 *table; | ||
42 | |||
43 | /* chip constraints on regulator behavior */ | ||
44 | u16 min_mV; | ||
45 | |||
46 | /* used by regulator core */ | ||
47 | struct regulator_desc desc; | ||
48 | }; | ||
49 | |||
50 | |||
51 | /* LDO control registers ... offset is from the base of its register bank. | ||
52 | * The first three registers of all power resource banks help hardware to | ||
53 | * manage the various resource groups. | ||
54 | */ | ||
55 | #define VREG_GRP 0 | ||
56 | #define VREG_TYPE 1 | ||
57 | #define VREG_REMAP 2 | ||
58 | #define VREG_DEDICATED 3 /* LDO control */ | ||
59 | |||
60 | |||
61 | static inline int | ||
62 | twl4030reg_read(struct twlreg_info *info, unsigned offset) | ||
63 | { | ||
64 | u8 value; | ||
65 | int status; | ||
66 | |||
67 | status = twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, | ||
68 | &value, info->base + offset); | ||
69 | return (status < 0) ? status : value; | ||
70 | } | ||
71 | |||
72 | static inline int | ||
73 | twl4030reg_write(struct twlreg_info *info, unsigned offset, u8 value) | ||
74 | { | ||
75 | return twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, | ||
76 | value, info->base + offset); | ||
77 | } | ||
78 | |||
79 | /*----------------------------------------------------------------------*/ | ||
80 | |||
81 | /* generic power resource operations, which work on all regulators */ | ||
82 | |||
83 | static int twl4030reg_grp(struct regulator_dev *rdev) | ||
84 | { | ||
85 | return twl4030reg_read(rdev_get_drvdata(rdev), VREG_GRP); | ||
86 | } | ||
87 | |||
88 | /* | ||
89 | * Enable/disable regulators by joining/leaving the P1 (processor) group. | ||
90 | * We assume nobody else is updating the DEV_GRP registers. | ||
91 | */ | ||
92 | |||
93 | #define P3_GRP BIT(7) /* "peripherals" */ | ||
94 | #define P2_GRP BIT(6) /* secondary processor, modem, etc */ | ||
95 | #define P1_GRP BIT(5) /* CPU/Linux */ | ||
96 | |||
97 | static int twl4030reg_is_enabled(struct regulator_dev *rdev) | ||
98 | { | ||
99 | int state = twl4030reg_grp(rdev); | ||
100 | |||
101 | if (state < 0) | ||
102 | return state; | ||
103 | |||
104 | return (state & P1_GRP) != 0; | ||
105 | } | ||
106 | |||
107 | static int twl4030reg_enable(struct regulator_dev *rdev) | ||
108 | { | ||
109 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
110 | int grp; | ||
111 | |||
112 | grp = twl4030reg_read(info, VREG_GRP); | ||
113 | if (grp < 0) | ||
114 | return grp; | ||
115 | |||
116 | grp |= P1_GRP; | ||
117 | return twl4030reg_write(info, VREG_GRP, grp); | ||
118 | } | ||
119 | |||
120 | static int twl4030reg_disable(struct regulator_dev *rdev) | ||
121 | { | ||
122 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
123 | int grp; | ||
124 | |||
125 | grp = twl4030reg_read(info, VREG_GRP); | ||
126 | if (grp < 0) | ||
127 | return grp; | ||
128 | |||
129 | grp &= ~P1_GRP; | ||
130 | return twl4030reg_write(info, VREG_GRP, grp); | ||
131 | } | ||
132 | |||
133 | static int twl4030reg_get_status(struct regulator_dev *rdev) | ||
134 | { | ||
135 | int state = twl4030reg_grp(rdev); | ||
136 | |||
137 | if (state < 0) | ||
138 | return state; | ||
139 | state &= 0x0f; | ||
140 | |||
141 | /* assume state != WARM_RESET; we'd not be running... */ | ||
142 | if (!state) | ||
143 | return REGULATOR_STATUS_OFF; | ||
144 | return (state & BIT(3)) | ||
145 | ? REGULATOR_STATUS_NORMAL | ||
146 | : REGULATOR_STATUS_STANDBY; | ||
147 | } | ||
148 | |||
149 | static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) | ||
150 | { | ||
151 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
152 | unsigned message; | ||
153 | int status; | ||
154 | |||
155 | /* We can only set the mode through state machine commands... */ | ||
156 | switch (mode) { | ||
157 | case REGULATOR_MODE_NORMAL: | ||
158 | message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); | ||
159 | break; | ||
160 | case REGULATOR_MODE_STANDBY: | ||
161 | message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP); | ||
162 | break; | ||
163 | default: | ||
164 | return -EINVAL; | ||
165 | } | ||
166 | |||
167 | /* Ensure the resource is associated with some group */ | ||
168 | status = twl4030reg_grp(rdev); | ||
169 | if (status < 0) | ||
170 | return status; | ||
171 | if (!(status & (P3_GRP | P2_GRP | P1_GRP))) | ||
172 | return -EACCES; | ||
173 | |||
174 | status = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, | ||
175 | message >> 8, 0x15 /* PB_WORD_MSB */ ); | ||
176 | if (status >= 0) | ||
177 | return status; | ||
178 | |||
179 | return twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, | ||
180 | message, 0x16 /* PB_WORD_LSB */ ); | ||
181 | } | ||
182 | |||
183 | /*----------------------------------------------------------------------*/ | ||
184 | |||
185 | /* | ||
186 | * Support for adjustable-voltage LDOs uses a four bit (or less) voltage | ||
187 | * select field in its control register. We use tables indexed by VSEL | ||
188 | * to record voltages in milliVolts. (Accuracy is about three percent.) | ||
189 | * | ||
190 | * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon; | ||
191 | * currently handled by listing two slightly different VAUX2 regulators, | ||
192 | * only one of which will be configured. | ||
193 | * | ||
194 | * VSEL values documented as "TI cannot support these values" are flagged | ||
195 | * in these tables as UNSUP() values; we normally won't assign them. | ||
196 | * | ||
197 | * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. | ||
198 | * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting. | ||
199 | */ | ||
200 | #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED | ||
201 | #define UNSUP_MASK 0x0000 | ||
202 | #else | ||
203 | #define UNSUP_MASK 0x8000 | ||
204 | #endif | ||
205 | |||
206 | #define UNSUP(x) (UNSUP_MASK | (x)) | ||
207 | #define IS_UNSUP(x) (UNSUP_MASK & (x)) | ||
208 | #define LDO_MV(x) (~UNSUP_MASK & (x)) | ||
209 | |||
210 | |||
211 | static const u16 VAUX1_VSEL_table[] = { | ||
212 | UNSUP(1500), UNSUP(1800), 2500, 2800, | ||
213 | 3000, 3000, 3000, 3000, | ||
214 | }; | ||
215 | static const u16 VAUX2_4030_VSEL_table[] = { | ||
216 | UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300, | ||
217 | 1500, 1800, UNSUP(1850), 2500, | ||
218 | UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), | ||
219 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), | ||
220 | }; | ||
221 | static const u16 VAUX2_VSEL_table[] = { | ||
222 | 1700, 1700, 1900, 1300, | ||
223 | 1500, 1800, 2000, 2500, | ||
224 | 2100, 2800, 2200, 2300, | ||
225 | 2400, 2400, 2400, 2400, | ||
226 | }; | ||
227 | static const u16 VAUX3_VSEL_table[] = { | ||
228 | 1500, 1800, 2500, 2800, | ||
229 | 3000, 3000, 3000, 3000, | ||
230 | }; | ||
231 | static const u16 VAUX4_VSEL_table[] = { | ||
232 | 700, 1000, 1200, UNSUP(1300), | ||
233 | 1500, 1800, UNSUP(1850), 2500, | ||
234 | UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), | ||
235 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), | ||
236 | }; | ||
237 | static const u16 VMMC1_VSEL_table[] = { | ||
238 | 1850, 2850, 3000, 3150, | ||
239 | }; | ||
240 | static const u16 VMMC2_VSEL_table[] = { | ||
241 | UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300), | ||
242 | UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500), | ||
243 | 2600, 2800, 2850, 3000, | ||
244 | 3150, 3150, 3150, 3150, | ||
245 | }; | ||
246 | static const u16 VPLL1_VSEL_table[] = { | ||
247 | 1000, 1200, 1300, 1800, | ||
248 | UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000), | ||
249 | }; | ||
250 | static const u16 VPLL2_VSEL_table[] = { | ||
251 | 700, 1000, 1200, 1300, | ||
252 | UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500), | ||
253 | UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000), | ||
254 | UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), | ||
255 | }; | ||
256 | static const u16 VSIM_VSEL_table[] = { | ||
257 | UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800, | ||
258 | 2800, 3000, 3000, 3000, | ||
259 | }; | ||
260 | static const u16 VDAC_VSEL_table[] = { | ||
261 | 1200, 1300, 1800, 1800, | ||
262 | }; | ||
263 | |||
264 | |||
265 | static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) | ||
266 | { | ||
267 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
268 | int mV = info->table[index]; | ||
269 | |||
270 | return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000); | ||
271 | } | ||
272 | |||
273 | static int | ||
274 | twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) | ||
275 | { | ||
276 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
277 | int vsel; | ||
278 | |||
279 | for (vsel = 0; vsel < info->table_len; vsel++) { | ||
280 | int mV = info->table[vsel]; | ||
281 | int uV; | ||
282 | |||
283 | if (IS_UNSUP(mV)) | ||
284 | continue; | ||
285 | uV = LDO_MV(mV) * 1000; | ||
286 | |||
287 | /* REVISIT for VAUX2, first match may not be best/lowest */ | ||
288 | |||
289 | /* use the first in-range value */ | ||
290 | if (min_uV <= uV && uV <= max_uV) | ||
291 | return twl4030reg_write(info, VREG_DEDICATED, vsel); | ||
292 | } | ||
293 | |||
294 | return -EDOM; | ||
295 | } | ||
296 | |||
297 | static int twl4030ldo_get_voltage(struct regulator_dev *rdev) | ||
298 | { | ||
299 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
300 | int vsel = twl4030reg_read(info, VREG_DEDICATED); | ||
301 | |||
302 | if (vsel < 0) | ||
303 | return vsel; | ||
304 | |||
305 | vsel &= info->table_len - 1; | ||
306 | return LDO_MV(info->table[vsel]) * 1000; | ||
307 | } | ||
308 | |||
309 | static struct regulator_ops twl4030ldo_ops = { | ||
310 | .list_voltage = twl4030ldo_list_voltage, | ||
311 | |||
312 | .set_voltage = twl4030ldo_set_voltage, | ||
313 | .get_voltage = twl4030ldo_get_voltage, | ||
314 | |||
315 | .enable = twl4030reg_enable, | ||
316 | .disable = twl4030reg_disable, | ||
317 | .is_enabled = twl4030reg_is_enabled, | ||
318 | |||
319 | .set_mode = twl4030reg_set_mode, | ||
320 | |||
321 | .get_status = twl4030reg_get_status, | ||
322 | }; | ||
323 | |||
324 | /*----------------------------------------------------------------------*/ | ||
325 | |||
326 | /* | ||
327 | * Fixed voltage LDOs don't have a VSEL field to update. | ||
328 | */ | ||
329 | static int twl4030fixed_list_voltage(struct regulator_dev *rdev, unsigned index) | ||
330 | { | ||
331 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
332 | |||
333 | return info->min_mV * 1000; | ||
334 | } | ||
335 | |||
336 | static int twl4030fixed_get_voltage(struct regulator_dev *rdev) | ||
337 | { | ||
338 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
339 | |||
340 | return info->min_mV * 1000; | ||
341 | } | ||
342 | |||
343 | static struct regulator_ops twl4030fixed_ops = { | ||
344 | .list_voltage = twl4030fixed_list_voltage, | ||
345 | |||
346 | .get_voltage = twl4030fixed_get_voltage, | ||
347 | |||
348 | .enable = twl4030reg_enable, | ||
349 | .disable = twl4030reg_disable, | ||
350 | .is_enabled = twl4030reg_is_enabled, | ||
351 | |||
352 | .set_mode = twl4030reg_set_mode, | ||
353 | |||
354 | .get_status = twl4030reg_get_status, | ||
355 | }; | ||
356 | |||
357 | /*----------------------------------------------------------------------*/ | ||
358 | |||
359 | #define TWL_ADJUSTABLE_LDO(label, offset, num) { \ | ||
360 | .base = offset, \ | ||
361 | .id = num, \ | ||
362 | .table_len = ARRAY_SIZE(label##_VSEL_table), \ | ||
363 | .table = label##_VSEL_table, \ | ||
364 | .desc = { \ | ||
365 | .name = #label, \ | ||
366 | .id = TWL4030_REG_##label, \ | ||
367 | .n_voltages = ARRAY_SIZE(label##_VSEL_table), \ | ||
368 | .ops = &twl4030ldo_ops, \ | ||
369 | .type = REGULATOR_VOLTAGE, \ | ||
370 | .owner = THIS_MODULE, \ | ||
371 | }, \ | ||
372 | } | ||
373 | |||
374 | #define TWL_FIXED_LDO(label, offset, mVolts, num) { \ | ||
375 | .base = offset, \ | ||
376 | .id = num, \ | ||
377 | .min_mV = mVolts, \ | ||
378 | .desc = { \ | ||
379 | .name = #label, \ | ||
380 | .id = TWL4030_REG_##label, \ | ||
381 | .n_voltages = 1, \ | ||
382 | .ops = &twl4030fixed_ops, \ | ||
383 | .type = REGULATOR_VOLTAGE, \ | ||
384 | .owner = THIS_MODULE, \ | ||
385 | }, \ | ||
386 | } | ||
387 | |||
388 | /* | ||
389 | * We list regulators here if systems need some level of | ||
390 | * software control over them after boot. | ||
391 | */ | ||
392 | static struct twlreg_info twl4030_regs[] = { | ||
393 | TWL_ADJUSTABLE_LDO(VAUX1, 0x17, 1), | ||
394 | TWL_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2), | ||
395 | TWL_ADJUSTABLE_LDO(VAUX2, 0x1b, 2), | ||
396 | TWL_ADJUSTABLE_LDO(VAUX3, 0x1f, 3), | ||
397 | TWL_ADJUSTABLE_LDO(VAUX4, 0x23, 4), | ||
398 | TWL_ADJUSTABLE_LDO(VMMC1, 0x27, 5), | ||
399 | TWL_ADJUSTABLE_LDO(VMMC2, 0x2b, 6), | ||
400 | /* | ||
401 | TWL_ADJUSTABLE_LDO(VPLL1, 0x2f, 7), | ||
402 | */ | ||
403 | TWL_ADJUSTABLE_LDO(VPLL2, 0x33, 8), | ||
404 | TWL_ADJUSTABLE_LDO(VSIM, 0x37, 9), | ||
405 | TWL_ADJUSTABLE_LDO(VDAC, 0x3b, 10), | ||
406 | /* | ||
407 | TWL_ADJUSTABLE_LDO(VINTANA1, 0x3f, 11), | ||
408 | TWL_ADJUSTABLE_LDO(VINTANA2, 0x43, 12), | ||
409 | TWL_ADJUSTABLE_LDO(VINTDIG, 0x47, 13), | ||
410 | TWL_SMPS(VIO, 0x4b, 14), | ||
411 | TWL_SMPS(VDD1, 0x55, 15), | ||
412 | TWL_SMPS(VDD2, 0x63, 16), | ||
413 | */ | ||
414 | TWL_FIXED_LDO(VUSB1V5, 0x71, 1500, 17), | ||
415 | TWL_FIXED_LDO(VUSB1V8, 0x74, 1800, 18), | ||
416 | TWL_FIXED_LDO(VUSB3V1, 0x77, 3100, 19), | ||
417 | /* VUSBCP is managed *only* by the USB subchip */ | ||
418 | }; | ||
419 | |||
420 | static int twl4030reg_probe(struct platform_device *pdev) | ||
421 | { | ||
422 | int i; | ||
423 | struct twlreg_info *info; | ||
424 | struct regulator_init_data *initdata; | ||
425 | struct regulation_constraints *c; | ||
426 | struct regulator_dev *rdev; | ||
427 | |||
428 | for (i = 0, info = NULL; i < ARRAY_SIZE(twl4030_regs); i++) { | ||
429 | if (twl4030_regs[i].desc.id != pdev->id) | ||
430 | continue; | ||
431 | info = twl4030_regs + i; | ||
432 | break; | ||
433 | } | ||
434 | if (!info) | ||
435 | return -ENODEV; | ||
436 | |||
437 | initdata = pdev->dev.platform_data; | ||
438 | if (!initdata) | ||
439 | return -EINVAL; | ||
440 | |||
441 | /* Constrain board-specific capabilities according to what | ||
442 | * this driver and the chip itself can actually do. | ||
443 | */ | ||
444 | c = &initdata->constraints; | ||
445 | c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY; | ||
446 | c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE | ||
447 | | REGULATOR_CHANGE_MODE | ||
448 | | REGULATOR_CHANGE_STATUS; | ||
449 | |||
450 | rdev = regulator_register(&info->desc, &pdev->dev, initdata, info); | ||
451 | if (IS_ERR(rdev)) { | ||
452 | dev_err(&pdev->dev, "can't register %s, %ld\n", | ||
453 | info->desc.name, PTR_ERR(rdev)); | ||
454 | return PTR_ERR(rdev); | ||
455 | } | ||
456 | platform_set_drvdata(pdev, rdev); | ||
457 | |||
458 | /* NOTE: many regulators support short-circuit IRQs (presentable | ||
459 | * as REGULATOR_OVER_CURRENT notifications?) configured via: | ||
460 | * - SC_CONFIG | ||
461 | * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4) | ||
462 | * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2) | ||
463 | * - IT_CONFIG | ||
464 | */ | ||
465 | |||
466 | return 0; | ||
467 | } | ||
468 | |||
469 | static int __devexit twl4030reg_remove(struct platform_device *pdev) | ||
470 | { | ||
471 | regulator_unregister(platform_get_drvdata(pdev)); | ||
472 | return 0; | ||
473 | } | ||
474 | |||
475 | MODULE_ALIAS("platform:twl4030_reg"); | ||
476 | |||
477 | static struct platform_driver twl4030reg_driver = { | ||
478 | .probe = twl4030reg_probe, | ||
479 | .remove = __devexit_p(twl4030reg_remove), | ||
480 | /* NOTE: short name, to work around driver model truncation of | ||
481 | * "twl4030_regulator.12" (and friends) to "twl4030_regulator.1". | ||
482 | */ | ||
483 | .driver.name = "twl4030_reg", | ||
484 | .driver.owner = THIS_MODULE, | ||
485 | }; | ||
486 | |||
487 | static int __init twl4030reg_init(void) | ||
488 | { | ||
489 | return platform_driver_register(&twl4030reg_driver); | ||
490 | } | ||
491 | subsys_initcall(twl4030reg_init); | ||
492 | |||
493 | static void __exit twl4030reg_exit(void) | ||
494 | { | ||
495 | platform_driver_unregister(&twl4030reg_driver); | ||
496 | } | ||
497 | module_exit(twl4030reg_exit) | ||
498 | |||
499 | MODULE_DESCRIPTION("TWL4030 regulator driver"); | ||
500 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c index 5ddb464b1c3f..3d08348584e1 100644 --- a/drivers/regulator/virtual.c +++ b/drivers/regulator/virtual.c | |||
@@ -226,13 +226,17 @@ static ssize_t set_mode(struct device *dev, struct device_attribute *attr, | |||
226 | unsigned int mode; | 226 | unsigned int mode; |
227 | int ret; | 227 | int ret; |
228 | 228 | ||
229 | if (strncmp(buf, "fast", strlen("fast")) == 0) | 229 | /* |
230 | * sysfs_streq() doesn't need the \n's, but we add them so the strings | ||
231 | * will be shared with show_mode(), above. | ||
232 | */ | ||
233 | if (sysfs_streq(buf, "fast\n") == 0) | ||
230 | mode = REGULATOR_MODE_FAST; | 234 | mode = REGULATOR_MODE_FAST; |
231 | else if (strncmp(buf, "normal", strlen("normal")) == 0) | 235 | else if (sysfs_streq(buf, "normal\n") == 0) |
232 | mode = REGULATOR_MODE_NORMAL; | 236 | mode = REGULATOR_MODE_NORMAL; |
233 | else if (strncmp(buf, "idle", strlen("idle")) == 0) | 237 | else if (sysfs_streq(buf, "idle\n") == 0) |
234 | mode = REGULATOR_MODE_IDLE; | 238 | mode = REGULATOR_MODE_IDLE; |
235 | else if (strncmp(buf, "standby", strlen("standby")) == 0) | 239 | else if (sysfs_streq(buf, "standby\n") == 0) |
236 | mode = REGULATOR_MODE_STANDBY; | 240 | mode = REGULATOR_MODE_STANDBY; |
237 | else { | 241 | else { |
238 | dev_err(dev, "Configuring invalid mode\n"); | 242 | dev_err(dev, "Configuring invalid mode\n"); |
@@ -256,7 +260,7 @@ static DEVICE_ATTR(min_microamps, 0666, show_min_uA, set_min_uA); | |||
256 | static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); | 260 | static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); |
257 | static DEVICE_ATTR(mode, 0666, show_mode, set_mode); | 261 | static DEVICE_ATTR(mode, 0666, show_mode, set_mode); |
258 | 262 | ||
259 | struct device_attribute *attributes[] = { | 263 | static struct device_attribute *attributes[] = { |
260 | &dev_attr_min_microvolts, | 264 | &dev_attr_min_microvolts, |
261 | &dev_attr_max_microvolts, | 265 | &dev_attr_max_microvolts, |
262 | &dev_attr_min_microamps, | 266 | &dev_attr_min_microamps, |
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index 5056e23e4414..771eca1066b5 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c | |||
@@ -24,6 +24,9 @@ | |||
24 | #include <linux/regulator/driver.h> | 24 | #include <linux/regulator/driver.h> |
25 | #include <linux/regulator/machine.h> | 25 | #include <linux/regulator/machine.h> |
26 | 26 | ||
27 | /* Maximum value possible for VSEL */ | ||
28 | #define WM8350_DCDC_MAX_VSEL 0x66 | ||
29 | |||
27 | /* Microamps */ | 30 | /* Microamps */ |
28 | static const int isink_cur[] = { | 31 | static const int isink_cur[] = { |
29 | 4, | 32 | 4, |
@@ -385,6 +388,14 @@ static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev) | |||
385 | return wm8350_dcdc_val_to_mvolts(val) * 1000; | 388 | return wm8350_dcdc_val_to_mvolts(val) * 1000; |
386 | } | 389 | } |
387 | 390 | ||
391 | static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev, | ||
392 | unsigned selector) | ||
393 | { | ||
394 | if (selector > WM8350_DCDC_MAX_VSEL) | ||
395 | return -EINVAL; | ||
396 | return wm8350_dcdc_val_to_mvolts(selector) * 1000; | ||
397 | } | ||
398 | |||
388 | static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) | 399 | static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
389 | { | 400 | { |
390 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | 401 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); |
@@ -775,6 +786,14 @@ static int wm8350_ldo_get_voltage(struct regulator_dev *rdev) | |||
775 | return wm8350_ldo_val_to_mvolts(val) * 1000; | 786 | return wm8350_ldo_val_to_mvolts(val) * 1000; |
776 | } | 787 | } |
777 | 788 | ||
789 | static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, | ||
790 | unsigned selector) | ||
791 | { | ||
792 | if (selector > WM8350_LDO1_VSEL_MASK) | ||
793 | return -EINVAL; | ||
794 | return wm8350_ldo_val_to_mvolts(selector) * 1000; | ||
795 | } | ||
796 | |||
778 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, | 797 | int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, |
779 | u16 stop, u16 fault) | 798 | u16 stop, u16 fault) |
780 | { | 799 | { |
@@ -1031,18 +1050,30 @@ static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev) | |||
1031 | int dcdc = rdev_get_id(rdev); | 1050 | int dcdc = rdev_get_id(rdev); |
1032 | u16 mask, sleep, active, force; | 1051 | u16 mask, sleep, active, force; |
1033 | int mode = REGULATOR_MODE_NORMAL; | 1052 | int mode = REGULATOR_MODE_NORMAL; |
1053 | int reg; | ||
1034 | 1054 | ||
1035 | if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6) | 1055 | switch (dcdc) { |
1036 | return -EINVAL; | 1056 | case WM8350_DCDC_1: |
1037 | 1057 | reg = WM8350_DCDC1_FORCE_PWM; | |
1038 | if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5) | 1058 | break; |
1059 | case WM8350_DCDC_3: | ||
1060 | reg = WM8350_DCDC3_FORCE_PWM; | ||
1061 | break; | ||
1062 | case WM8350_DCDC_4: | ||
1063 | reg = WM8350_DCDC4_FORCE_PWM; | ||
1064 | break; | ||
1065 | case WM8350_DCDC_6: | ||
1066 | reg = WM8350_DCDC6_FORCE_PWM; | ||
1067 | break; | ||
1068 | default: | ||
1039 | return -EINVAL; | 1069 | return -EINVAL; |
1070 | } | ||
1040 | 1071 | ||
1041 | mask = 1 << (dcdc - WM8350_DCDC_1); | 1072 | mask = 1 << (dcdc - WM8350_DCDC_1); |
1042 | active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask; | 1073 | active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask; |
1074 | force = wm8350_reg_read(wm8350, reg) & WM8350_DCDC1_FORCE_PWM_ENA; | ||
1043 | sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask; | 1075 | sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask; |
1044 | force = wm8350_reg_read(wm8350, WM8350_DCDC1_FORCE_PWM) | 1076 | |
1045 | & WM8350_DCDC1_FORCE_PWM_ENA; | ||
1046 | dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x", | 1077 | dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x", |
1047 | mask, active, sleep, force); | 1078 | mask, active, sleep, force); |
1048 | 1079 | ||
@@ -1150,6 +1181,7 @@ static int wm8350_ldo_is_enabled(struct regulator_dev *rdev) | |||
1150 | static struct regulator_ops wm8350_dcdc_ops = { | 1181 | static struct regulator_ops wm8350_dcdc_ops = { |
1151 | .set_voltage = wm8350_dcdc_set_voltage, | 1182 | .set_voltage = wm8350_dcdc_set_voltage, |
1152 | .get_voltage = wm8350_dcdc_get_voltage, | 1183 | .get_voltage = wm8350_dcdc_get_voltage, |
1184 | .list_voltage = wm8350_dcdc_list_voltage, | ||
1153 | .enable = wm8350_dcdc_enable, | 1185 | .enable = wm8350_dcdc_enable, |
1154 | .disable = wm8350_dcdc_disable, | 1186 | .disable = wm8350_dcdc_disable, |
1155 | .get_mode = wm8350_dcdc_get_mode, | 1187 | .get_mode = wm8350_dcdc_get_mode, |
@@ -1173,6 +1205,7 @@ static struct regulator_ops wm8350_dcdc2_5_ops = { | |||
1173 | static struct regulator_ops wm8350_ldo_ops = { | 1205 | static struct regulator_ops wm8350_ldo_ops = { |
1174 | .set_voltage = wm8350_ldo_set_voltage, | 1206 | .set_voltage = wm8350_ldo_set_voltage, |
1175 | .get_voltage = wm8350_ldo_get_voltage, | 1207 | .get_voltage = wm8350_ldo_get_voltage, |
1208 | .list_voltage = wm8350_ldo_list_voltage, | ||
1176 | .enable = wm8350_ldo_enable, | 1209 | .enable = wm8350_ldo_enable, |
1177 | .disable = wm8350_ldo_disable, | 1210 | .disable = wm8350_ldo_disable, |
1178 | .is_enabled = wm8350_ldo_is_enabled, | 1211 | .is_enabled = wm8350_ldo_is_enabled, |
@@ -1197,6 +1230,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1197 | .ops = &wm8350_dcdc_ops, | 1230 | .ops = &wm8350_dcdc_ops, |
1198 | .irq = WM8350_IRQ_UV_DC1, | 1231 | .irq = WM8350_IRQ_UV_DC1, |
1199 | .type = REGULATOR_VOLTAGE, | 1232 | .type = REGULATOR_VOLTAGE, |
1233 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | ||
1200 | .owner = THIS_MODULE, | 1234 | .owner = THIS_MODULE, |
1201 | }, | 1235 | }, |
1202 | { | 1236 | { |
@@ -1213,6 +1247,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1213 | .ops = &wm8350_dcdc_ops, | 1247 | .ops = &wm8350_dcdc_ops, |
1214 | .irq = WM8350_IRQ_UV_DC3, | 1248 | .irq = WM8350_IRQ_UV_DC3, |
1215 | .type = REGULATOR_VOLTAGE, | 1249 | .type = REGULATOR_VOLTAGE, |
1250 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | ||
1216 | .owner = THIS_MODULE, | 1251 | .owner = THIS_MODULE, |
1217 | }, | 1252 | }, |
1218 | { | 1253 | { |
@@ -1221,6 +1256,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1221 | .ops = &wm8350_dcdc_ops, | 1256 | .ops = &wm8350_dcdc_ops, |
1222 | .irq = WM8350_IRQ_UV_DC4, | 1257 | .irq = WM8350_IRQ_UV_DC4, |
1223 | .type = REGULATOR_VOLTAGE, | 1258 | .type = REGULATOR_VOLTAGE, |
1259 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | ||
1224 | .owner = THIS_MODULE, | 1260 | .owner = THIS_MODULE, |
1225 | }, | 1261 | }, |
1226 | { | 1262 | { |
@@ -1237,6 +1273,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1237 | .ops = &wm8350_dcdc_ops, | 1273 | .ops = &wm8350_dcdc_ops, |
1238 | .irq = WM8350_IRQ_UV_DC6, | 1274 | .irq = WM8350_IRQ_UV_DC6, |
1239 | .type = REGULATOR_VOLTAGE, | 1275 | .type = REGULATOR_VOLTAGE, |
1276 | .n_voltages = WM8350_DCDC_MAX_VSEL + 1, | ||
1240 | .owner = THIS_MODULE, | 1277 | .owner = THIS_MODULE, |
1241 | }, | 1278 | }, |
1242 | { | 1279 | { |
@@ -1245,6 +1282,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1245 | .ops = &wm8350_ldo_ops, | 1282 | .ops = &wm8350_ldo_ops, |
1246 | .irq = WM8350_IRQ_UV_LDO1, | 1283 | .irq = WM8350_IRQ_UV_LDO1, |
1247 | .type = REGULATOR_VOLTAGE, | 1284 | .type = REGULATOR_VOLTAGE, |
1285 | .n_voltages = WM8350_LDO1_VSEL_MASK + 1, | ||
1248 | .owner = THIS_MODULE, | 1286 | .owner = THIS_MODULE, |
1249 | }, | 1287 | }, |
1250 | { | 1288 | { |
@@ -1253,6 +1291,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1253 | .ops = &wm8350_ldo_ops, | 1291 | .ops = &wm8350_ldo_ops, |
1254 | .irq = WM8350_IRQ_UV_LDO2, | 1292 | .irq = WM8350_IRQ_UV_LDO2, |
1255 | .type = REGULATOR_VOLTAGE, | 1293 | .type = REGULATOR_VOLTAGE, |
1294 | .n_voltages = WM8350_LDO2_VSEL_MASK + 1, | ||
1256 | .owner = THIS_MODULE, | 1295 | .owner = THIS_MODULE, |
1257 | }, | 1296 | }, |
1258 | { | 1297 | { |
@@ -1261,6 +1300,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1261 | .ops = &wm8350_ldo_ops, | 1300 | .ops = &wm8350_ldo_ops, |
1262 | .irq = WM8350_IRQ_UV_LDO3, | 1301 | .irq = WM8350_IRQ_UV_LDO3, |
1263 | .type = REGULATOR_VOLTAGE, | 1302 | .type = REGULATOR_VOLTAGE, |
1303 | .n_voltages = WM8350_LDO3_VSEL_MASK + 1, | ||
1264 | .owner = THIS_MODULE, | 1304 | .owner = THIS_MODULE, |
1265 | }, | 1305 | }, |
1266 | { | 1306 | { |
@@ -1269,6 +1309,7 @@ static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1269 | .ops = &wm8350_ldo_ops, | 1309 | .ops = &wm8350_ldo_ops, |
1270 | .irq = WM8350_IRQ_UV_LDO4, | 1310 | .irq = WM8350_IRQ_UV_LDO4, |
1271 | .type = REGULATOR_VOLTAGE, | 1311 | .type = REGULATOR_VOLTAGE, |
1312 | .n_voltages = WM8350_LDO4_VSEL_MASK + 1, | ||
1272 | .owner = THIS_MODULE, | 1313 | .owner = THIS_MODULE, |
1273 | }, | 1314 | }, |
1274 | { | 1315 | { |
@@ -1293,6 +1334,7 @@ static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data) | |||
1293 | { | 1334 | { |
1294 | struct regulator_dev *rdev = (struct regulator_dev *)data; | 1335 | struct regulator_dev *rdev = (struct regulator_dev *)data; |
1295 | 1336 | ||
1337 | mutex_lock(&rdev->mutex); | ||
1296 | if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) | 1338 | if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2) |
1297 | regulator_notifier_call_chain(rdev, | 1339 | regulator_notifier_call_chain(rdev, |
1298 | REGULATOR_EVENT_REGULATION_OUT, | 1340 | REGULATOR_EVENT_REGULATION_OUT, |
@@ -1301,6 +1343,7 @@ static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data) | |||
1301 | regulator_notifier_call_chain(rdev, | 1343 | regulator_notifier_call_chain(rdev, |
1302 | REGULATOR_EVENT_UNDER_VOLTAGE, | 1344 | REGULATOR_EVENT_UNDER_VOLTAGE, |
1303 | wm8350); | 1345 | wm8350); |
1346 | mutex_unlock(&rdev->mutex); | ||
1304 | } | 1347 | } |
1305 | 1348 | ||
1306 | static int wm8350_regulator_probe(struct platform_device *pdev) | 1349 | static int wm8350_regulator_probe(struct platform_device *pdev) |
@@ -1333,9 +1376,9 @@ static int wm8350_regulator_probe(struct platform_device *pdev) | |||
1333 | break; | 1376 | break; |
1334 | } | 1377 | } |
1335 | 1378 | ||
1336 | |||
1337 | /* register regulator */ | 1379 | /* register regulator */ |
1338 | rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev, | 1380 | rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev, |
1381 | pdev->dev.platform_data, | ||
1339 | dev_get_drvdata(&pdev->dev)); | 1382 | dev_get_drvdata(&pdev->dev)); |
1340 | if (IS_ERR(rdev)) { | 1383 | if (IS_ERR(rdev)) { |
1341 | dev_err(&pdev->dev, "failed to register %s\n", | 1384 | dev_err(&pdev->dev, "failed to register %s\n", |
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index 56e23d44ba59..157426029071 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c | |||
@@ -43,6 +43,18 @@ static int wm8400_ldo_disable(struct regulator_dev *dev) | |||
43 | WM8400_LDO1_ENA, 0); | 43 | WM8400_LDO1_ENA, 0); |
44 | } | 44 | } |
45 | 45 | ||
46 | static int wm8400_ldo_list_voltage(struct regulator_dev *dev, | ||
47 | unsigned selector) | ||
48 | { | ||
49 | if (selector > WM8400_LDO1_VSEL_MASK) | ||
50 | return -EINVAL; | ||
51 | |||
52 | if (selector < 15) | ||
53 | return 900000 + (selector * 50000); | ||
54 | else | ||
55 | return 1600000 + ((selector - 14) * 100000); | ||
56 | } | ||
57 | |||
46 | static int wm8400_ldo_get_voltage(struct regulator_dev *dev) | 58 | static int wm8400_ldo_get_voltage(struct regulator_dev *dev) |
47 | { | 59 | { |
48 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | 60 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); |
@@ -51,10 +63,7 @@ static int wm8400_ldo_get_voltage(struct regulator_dev *dev) | |||
51 | val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); | 63 | val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); |
52 | val &= WM8400_LDO1_VSEL_MASK; | 64 | val &= WM8400_LDO1_VSEL_MASK; |
53 | 65 | ||
54 | if (val < 15) | 66 | return wm8400_ldo_list_voltage(dev, val); |
55 | return 900000 + (val * 50000); | ||
56 | else | ||
57 | return 1600000 + ((val - 14) * 100000); | ||
58 | } | 67 | } |
59 | 68 | ||
60 | static int wm8400_ldo_set_voltage(struct regulator_dev *dev, | 69 | static int wm8400_ldo_set_voltage(struct regulator_dev *dev, |
@@ -92,6 +101,7 @@ static struct regulator_ops wm8400_ldo_ops = { | |||
92 | .is_enabled = wm8400_ldo_is_enabled, | 101 | .is_enabled = wm8400_ldo_is_enabled, |
93 | .enable = wm8400_ldo_enable, | 102 | .enable = wm8400_ldo_enable, |
94 | .disable = wm8400_ldo_disable, | 103 | .disable = wm8400_ldo_disable, |
104 | .list_voltage = wm8400_ldo_list_voltage, | ||
95 | .get_voltage = wm8400_ldo_get_voltage, | 105 | .get_voltage = wm8400_ldo_get_voltage, |
96 | .set_voltage = wm8400_ldo_set_voltage, | 106 | .set_voltage = wm8400_ldo_set_voltage, |
97 | }; | 107 | }; |
@@ -124,6 +134,15 @@ static int wm8400_dcdc_disable(struct regulator_dev *dev) | |||
124 | WM8400_DC1_ENA, 0); | 134 | WM8400_DC1_ENA, 0); |
125 | } | 135 | } |
126 | 136 | ||
137 | static int wm8400_dcdc_list_voltage(struct regulator_dev *dev, | ||
138 | unsigned selector) | ||
139 | { | ||
140 | if (selector > WM8400_DC1_VSEL_MASK) | ||
141 | return -EINVAL; | ||
142 | |||
143 | return 850000 + (selector * 25000); | ||
144 | } | ||
145 | |||
127 | static int wm8400_dcdc_get_voltage(struct regulator_dev *dev) | 146 | static int wm8400_dcdc_get_voltage(struct regulator_dev *dev) |
128 | { | 147 | { |
129 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | 148 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); |
@@ -237,6 +256,7 @@ static struct regulator_ops wm8400_dcdc_ops = { | |||
237 | .is_enabled = wm8400_dcdc_is_enabled, | 256 | .is_enabled = wm8400_dcdc_is_enabled, |
238 | .enable = wm8400_dcdc_enable, | 257 | .enable = wm8400_dcdc_enable, |
239 | .disable = wm8400_dcdc_disable, | 258 | .disable = wm8400_dcdc_disable, |
259 | .list_voltage = wm8400_dcdc_list_voltage, | ||
240 | .get_voltage = wm8400_dcdc_get_voltage, | 260 | .get_voltage = wm8400_dcdc_get_voltage, |
241 | .set_voltage = wm8400_dcdc_set_voltage, | 261 | .set_voltage = wm8400_dcdc_set_voltage, |
242 | .get_mode = wm8400_dcdc_get_mode, | 262 | .get_mode = wm8400_dcdc_get_mode, |
@@ -249,6 +269,7 @@ static struct regulator_desc regulators[] = { | |||
249 | .name = "LDO1", | 269 | .name = "LDO1", |
250 | .id = WM8400_LDO1, | 270 | .id = WM8400_LDO1, |
251 | .ops = &wm8400_ldo_ops, | 271 | .ops = &wm8400_ldo_ops, |
272 | .n_voltages = WM8400_LDO1_VSEL_MASK + 1, | ||
252 | .type = REGULATOR_VOLTAGE, | 273 | .type = REGULATOR_VOLTAGE, |
253 | .owner = THIS_MODULE, | 274 | .owner = THIS_MODULE, |
254 | }, | 275 | }, |
@@ -256,6 +277,7 @@ static struct regulator_desc regulators[] = { | |||
256 | .name = "LDO2", | 277 | .name = "LDO2", |
257 | .id = WM8400_LDO2, | 278 | .id = WM8400_LDO2, |
258 | .ops = &wm8400_ldo_ops, | 279 | .ops = &wm8400_ldo_ops, |
280 | .n_voltages = WM8400_LDO2_VSEL_MASK + 1, | ||
259 | .type = REGULATOR_VOLTAGE, | 281 | .type = REGULATOR_VOLTAGE, |
260 | .owner = THIS_MODULE, | 282 | .owner = THIS_MODULE, |
261 | }, | 283 | }, |
@@ -263,6 +285,7 @@ static struct regulator_desc regulators[] = { | |||
263 | .name = "LDO3", | 285 | .name = "LDO3", |
264 | .id = WM8400_LDO3, | 286 | .id = WM8400_LDO3, |
265 | .ops = &wm8400_ldo_ops, | 287 | .ops = &wm8400_ldo_ops, |
288 | .n_voltages = WM8400_LDO3_VSEL_MASK + 1, | ||
266 | .type = REGULATOR_VOLTAGE, | 289 | .type = REGULATOR_VOLTAGE, |
267 | .owner = THIS_MODULE, | 290 | .owner = THIS_MODULE, |
268 | }, | 291 | }, |
@@ -270,6 +293,7 @@ static struct regulator_desc regulators[] = { | |||
270 | .name = "LDO4", | 293 | .name = "LDO4", |
271 | .id = WM8400_LDO4, | 294 | .id = WM8400_LDO4, |
272 | .ops = &wm8400_ldo_ops, | 295 | .ops = &wm8400_ldo_ops, |
296 | .n_voltages = WM8400_LDO4_VSEL_MASK + 1, | ||
273 | .type = REGULATOR_VOLTAGE, | 297 | .type = REGULATOR_VOLTAGE, |
274 | .owner = THIS_MODULE, | 298 | .owner = THIS_MODULE, |
275 | }, | 299 | }, |
@@ -277,6 +301,7 @@ static struct regulator_desc regulators[] = { | |||
277 | .name = "DCDC1", | 301 | .name = "DCDC1", |
278 | .id = WM8400_DCDC1, | 302 | .id = WM8400_DCDC1, |
279 | .ops = &wm8400_dcdc_ops, | 303 | .ops = &wm8400_dcdc_ops, |
304 | .n_voltages = WM8400_DC1_VSEL_MASK + 1, | ||
280 | .type = REGULATOR_VOLTAGE, | 305 | .type = REGULATOR_VOLTAGE, |
281 | .owner = THIS_MODULE, | 306 | .owner = THIS_MODULE, |
282 | }, | 307 | }, |
@@ -284,6 +309,7 @@ static struct regulator_desc regulators[] = { | |||
284 | .name = "DCDC2", | 309 | .name = "DCDC2", |
285 | .id = WM8400_DCDC2, | 310 | .id = WM8400_DCDC2, |
286 | .ops = &wm8400_dcdc_ops, | 311 | .ops = &wm8400_dcdc_ops, |
312 | .n_voltages = WM8400_DC2_VSEL_MASK + 1, | ||
287 | .type = REGULATOR_VOLTAGE, | 313 | .type = REGULATOR_VOLTAGE, |
288 | .owner = THIS_MODULE, | 314 | .owner = THIS_MODULE, |
289 | }, | 315 | }, |
@@ -294,7 +320,7 @@ static int __devinit wm8400_regulator_probe(struct platform_device *pdev) | |||
294 | struct regulator_dev *rdev; | 320 | struct regulator_dev *rdev; |
295 | 321 | ||
296 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, | 322 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, |
297 | pdev->dev.driver_data); | 323 | pdev->dev.platform_data, pdev->dev.driver_data); |
298 | 324 | ||
299 | if (IS_ERR(rdev)) | 325 | if (IS_ERR(rdev)) |
300 | return PTR_ERR(rdev); | 326 | return PTR_ERR(rdev); |
diff --git a/include/linux/i2c/twl4030.h b/include/linux/i2c/twl4030.h index 8137f660a5cc..0dc80ef24975 100644 --- a/include/linux/i2c/twl4030.h +++ b/include/linux/i2c/twl4030.h | |||
@@ -218,6 +218,53 @@ int twl4030_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes); | |||
218 | 218 | ||
219 | /*----------------------------------------------------------------------*/ | 219 | /*----------------------------------------------------------------------*/ |
220 | 220 | ||
221 | /* Power bus message definitions */ | ||
222 | |||
223 | #define DEV_GRP_NULL 0x0 | ||
224 | #define DEV_GRP_P1 0x1 | ||
225 | #define DEV_GRP_P2 0x2 | ||
226 | #define DEV_GRP_P3 0x4 | ||
227 | |||
228 | #define RES_GRP_RES 0x0 | ||
229 | #define RES_GRP_PP 0x1 | ||
230 | #define RES_GRP_RC 0x2 | ||
231 | #define RES_GRP_PP_RC 0x3 | ||
232 | #define RES_GRP_PR 0x4 | ||
233 | #define RES_GRP_PP_PR 0x5 | ||
234 | #define RES_GRP_RC_PR 0x6 | ||
235 | #define RES_GRP_ALL 0x7 | ||
236 | |||
237 | #define RES_TYPE2_R0 0x0 | ||
238 | |||
239 | #define RES_TYPE_ALL 0x7 | ||
240 | |||
241 | #define RES_STATE_WRST 0xF | ||
242 | #define RES_STATE_ACTIVE 0xE | ||
243 | #define RES_STATE_SLEEP 0x8 | ||
244 | #define RES_STATE_OFF 0x0 | ||
245 | |||
246 | /* | ||
247 | * Power Bus Message Format ... these can be sent individually by Linux, | ||
248 | * but are usually part of downloaded scripts that are run when various | ||
249 | * power events are triggered. | ||
250 | * | ||
251 | * Broadcast Message (16 Bits): | ||
252 | * DEV_GRP[15:13] MT[12] RES_GRP[11:9] RES_TYPE2[8:7] RES_TYPE[6:4] | ||
253 | * RES_STATE[3:0] | ||
254 | * | ||
255 | * Singular Message (16 Bits): | ||
256 | * DEV_GRP[15:13] MT[12] RES_ID[11:4] RES_STATE[3:0] | ||
257 | */ | ||
258 | |||
259 | #define MSG_BROADCAST(devgrp, grp, type, type2, state) \ | ||
260 | ( (devgrp) << 13 | 1 << 12 | (grp) << 9 | (type2) << 7 \ | ||
261 | | (type) << 4 | (state)) | ||
262 | |||
263 | #define MSG_SINGULAR(devgrp, id, state) \ | ||
264 | ((devgrp) << 13 | 0 << 12 | (id) << 4 | (state)) | ||
265 | |||
266 | /*----------------------------------------------------------------------*/ | ||
267 | |||
221 | struct twl4030_bci_platform_data { | 268 | struct twl4030_bci_platform_data { |
222 | int *battery_tmp_tbl; | 269 | int *battery_tmp_tbl; |
223 | unsigned int tblsize; | 270 | unsigned int tblsize; |
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 4e457256bd33..3e7615e9087e 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h | |||
@@ -192,5 +192,10 @@ static inline void mmc_signal_sdio_irq(struct mmc_host *host) | |||
192 | wake_up_process(host->sdio_irq_thread); | 192 | wake_up_process(host->sdio_irq_thread); |
193 | } | 193 | } |
194 | 194 | ||
195 | struct regulator; | ||
196 | |||
197 | int mmc_regulator_get_ocrmask(struct regulator *supply); | ||
198 | int mmc_regulator_set_ocr(struct regulator *supply, unsigned short vdd_bit); | ||
199 | |||
195 | #endif | 200 | #endif |
196 | 201 | ||
diff --git a/include/linux/regulator/bq24022.h b/include/linux/regulator/bq24022.h index e84b0a9feda5..a6d014005d49 100644 --- a/include/linux/regulator/bq24022.h +++ b/include/linux/regulator/bq24022.h | |||
@@ -10,6 +10,8 @@ | |||
10 | * | 10 | * |
11 | */ | 11 | */ |
12 | 12 | ||
13 | struct regulator_init_data; | ||
14 | |||
13 | /** | 15 | /** |
14 | * bq24022_mach_info - platform data for bq24022 | 16 | * bq24022_mach_info - platform data for bq24022 |
15 | * @gpio_nce: GPIO line connected to the nCE pin, used to enable / disable charging | 17 | * @gpio_nce: GPIO line connected to the nCE pin, used to enable / disable charging |
@@ -18,4 +20,5 @@ | |||
18 | struct bq24022_mach_info { | 20 | struct bq24022_mach_info { |
19 | int gpio_nce; | 21 | int gpio_nce; |
20 | int gpio_iset2; | 22 | int gpio_iset2; |
23 | struct regulator_init_data *init_data; | ||
21 | }; | 24 | }; |
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 801bf77ff4e2..277f4b964df5 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | 4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. |
5 | * | 5 | * |
6 | * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 6 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 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 | 9 | * it under the terms of the GNU General Public License version 2 as |
@@ -88,6 +88,7 @@ | |||
88 | * FAIL Regulator output has failed. | 88 | * FAIL Regulator output has failed. |
89 | * OVER_TEMP Regulator over temp. | 89 | * OVER_TEMP Regulator over temp. |
90 | * FORCE_DISABLE Regulator shut down by software. | 90 | * FORCE_DISABLE Regulator shut down by software. |
91 | * VOLTAGE_CHANGE Regulator voltage changed. | ||
91 | * | 92 | * |
92 | * NOTE: These events can be OR'ed together when passed into handler. | 93 | * NOTE: These events can be OR'ed together when passed into handler. |
93 | */ | 94 | */ |
@@ -98,6 +99,7 @@ | |||
98 | #define REGULATOR_EVENT_FAIL 0x08 | 99 | #define REGULATOR_EVENT_FAIL 0x08 |
99 | #define REGULATOR_EVENT_OVER_TEMP 0x10 | 100 | #define REGULATOR_EVENT_OVER_TEMP 0x10 |
100 | #define REGULATOR_EVENT_FORCE_DISABLE 0x20 | 101 | #define REGULATOR_EVENT_FORCE_DISABLE 0x20 |
102 | #define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40 | ||
101 | 103 | ||
102 | struct regulator; | 104 | struct regulator; |
103 | 105 | ||
@@ -140,6 +142,8 @@ int regulator_bulk_disable(int num_consumers, | |||
140 | void regulator_bulk_free(int num_consumers, | 142 | void regulator_bulk_free(int num_consumers, |
141 | struct regulator_bulk_data *consumers); | 143 | struct regulator_bulk_data *consumers); |
142 | 144 | ||
145 | int regulator_count_voltages(struct regulator *regulator); | ||
146 | int regulator_list_voltage(struct regulator *regulator, unsigned selector); | ||
143 | int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); | 147 | int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); |
144 | int regulator_get_voltage(struct regulator *regulator); | 148 | int regulator_get_voltage(struct regulator *regulator); |
145 | int regulator_set_current_limit(struct regulator *regulator, | 149 | int regulator_set_current_limit(struct regulator *regulator, |
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 2dae05705f13..4848d8dacd90 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | 4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. |
5 | * | 5 | * |
6 | * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 6 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 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 | 9 | * it under the terms of the GNU General Public License version 2 as |
@@ -21,25 +21,38 @@ | |||
21 | struct regulator_dev; | 21 | struct regulator_dev; |
22 | struct regulator_init_data; | 22 | struct regulator_init_data; |
23 | 23 | ||
24 | enum regulator_status { | ||
25 | REGULATOR_STATUS_OFF, | ||
26 | REGULATOR_STATUS_ON, | ||
27 | REGULATOR_STATUS_ERROR, | ||
28 | /* fast/normal/idle/standby are flavors of "on" */ | ||
29 | REGULATOR_STATUS_FAST, | ||
30 | REGULATOR_STATUS_NORMAL, | ||
31 | REGULATOR_STATUS_IDLE, | ||
32 | REGULATOR_STATUS_STANDBY, | ||
33 | }; | ||
34 | |||
24 | /** | 35 | /** |
25 | * struct regulator_ops - regulator operations. | 36 | * struct regulator_ops - regulator operations. |
26 | * | 37 | * |
27 | * This struct describes regulator operations which can be implemented by | 38 | * @enable: Configure the regulator as enabled. |
28 | * regulator chip drivers. | 39 | * @disable: Configure the regulator as disabled. |
29 | * | ||
30 | * @enable: Enable the regulator. | ||
31 | * @disable: Disable the regulator. | ||
32 | * @is_enabled: Return 1 if the regulator is enabled, 0 otherwise. | 40 | * @is_enabled: Return 1 if the regulator is enabled, 0 otherwise. |
33 | * | 41 | * |
34 | * @set_voltage: Set the voltage for the regulator within the range specified. | 42 | * @set_voltage: Set the voltage for the regulator within the range specified. |
35 | * The driver should select the voltage closest to min_uV. | 43 | * The driver should select the voltage closest to min_uV. |
36 | * @get_voltage: Return the currently configured voltage for the regulator. | 44 | * @get_voltage: Return the currently configured voltage for the regulator. |
45 | * @list_voltage: Return one of the supported voltages, in microvolts; zero | ||
46 | * if the selector indicates a voltage that is unusable on this system; | ||
47 | * or negative errno. Selectors range from zero to one less than | ||
48 | * regulator_desc.n_voltages. Voltages may be reported in any order. | ||
37 | * | 49 | * |
38 | * @set_current_limit: Configure a limit for a current-limited regulator. | 50 | * @set_current_limit: Configure a limit for a current-limited regulator. |
39 | * @get_current_limit: Get the limit for a current-limited regulator. | 51 | * @get_current_limit: Get the configured limit for a current-limited regulator. |
40 | * | 52 | * |
41 | * @set_mode: Set the operating mode for the regulator. | 53 | * @get_mode: Get the configured operating mode for the regulator. |
42 | * @get_mode: Get the current operating mode for the regulator. | 54 | * @get_status: Return actual (not as-configured) status of regulator, as a |
55 | * REGULATOR_STATUS value (or negative errno) | ||
43 | * @get_optimum_mode: Get the most efficient operating mode for the regulator | 56 | * @get_optimum_mode: Get the most efficient operating mode for the regulator |
44 | * when running with the specified parameters. | 57 | * when running with the specified parameters. |
45 | * | 58 | * |
@@ -51,9 +64,15 @@ struct regulator_init_data; | |||
51 | * suspended. | 64 | * suspended. |
52 | * @set_suspend_mode: Set the operating mode for the regulator when the | 65 | * @set_suspend_mode: Set the operating mode for the regulator when the |
53 | * system is suspended. | 66 | * system is suspended. |
67 | * | ||
68 | * This struct describes regulator operations which can be implemented by | ||
69 | * regulator chip drivers. | ||
54 | */ | 70 | */ |
55 | struct regulator_ops { | 71 | struct regulator_ops { |
56 | 72 | ||
73 | /* enumerate supported voltages */ | ||
74 | int (*list_voltage) (struct regulator_dev *, unsigned selector); | ||
75 | |||
57 | /* get/set regulator voltage */ | 76 | /* get/set regulator voltage */ |
58 | int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV); | 77 | int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV); |
59 | int (*get_voltage) (struct regulator_dev *); | 78 | int (*get_voltage) (struct regulator_dev *); |
@@ -72,6 +91,13 @@ struct regulator_ops { | |||
72 | int (*set_mode) (struct regulator_dev *, unsigned int mode); | 91 | int (*set_mode) (struct regulator_dev *, unsigned int mode); |
73 | unsigned int (*get_mode) (struct regulator_dev *); | 92 | unsigned int (*get_mode) (struct regulator_dev *); |
74 | 93 | ||
94 | /* report regulator status ... most other accessors report | ||
95 | * control inputs, this reports results of combining inputs | ||
96 | * from Linux (and other sources) with the actual load. | ||
97 | * returns REGULATOR_STATUS_* or negative errno. | ||
98 | */ | ||
99 | int (*get_status)(struct regulator_dev *); | ||
100 | |||
75 | /* get most efficient regulator operating mode for load */ | 101 | /* get most efficient regulator operating mode for load */ |
76 | unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, | 102 | unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, |
77 | int output_uV, int load_uA); | 103 | int output_uV, int load_uA); |
@@ -106,6 +132,7 @@ enum regulator_type { | |||
106 | * | 132 | * |
107 | * @name: Identifying name for the regulator. | 133 | * @name: Identifying name for the regulator. |
108 | * @id: Numerical identifier for the regulator. | 134 | * @id: Numerical identifier for the regulator. |
135 | * @n_voltages: Number of selectors available for ops.list_voltage(). | ||
109 | * @ops: Regulator operations table. | 136 | * @ops: Regulator operations table. |
110 | * @irq: Interrupt number for the regulator. | 137 | * @irq: Interrupt number for the regulator. |
111 | * @type: Indicates if the regulator is a voltage or current regulator. | 138 | * @type: Indicates if the regulator is a voltage or current regulator. |
@@ -114,14 +141,48 @@ enum regulator_type { | |||
114 | struct regulator_desc { | 141 | struct regulator_desc { |
115 | const char *name; | 142 | const char *name; |
116 | int id; | 143 | int id; |
144 | unsigned n_voltages; | ||
117 | struct regulator_ops *ops; | 145 | struct regulator_ops *ops; |
118 | int irq; | 146 | int irq; |
119 | enum regulator_type type; | 147 | enum regulator_type type; |
120 | struct module *owner; | 148 | struct module *owner; |
121 | }; | 149 | }; |
122 | 150 | ||
151 | /* | ||
152 | * struct regulator_dev | ||
153 | * | ||
154 | * Voltage / Current regulator class device. One for each | ||
155 | * regulator. | ||
156 | * | ||
157 | * This should *not* be used directly by anything except the regulator | ||
158 | * core and notification injection (which should take the mutex and do | ||
159 | * no other direct access). | ||
160 | */ | ||
161 | struct regulator_dev { | ||
162 | struct regulator_desc *desc; | ||
163 | int use_count; | ||
164 | |||
165 | /* lists we belong to */ | ||
166 | struct list_head list; /* list of all regulators */ | ||
167 | struct list_head slist; /* list of supplied regulators */ | ||
168 | |||
169 | /* lists we own */ | ||
170 | struct list_head consumer_list; /* consumers we supply */ | ||
171 | struct list_head supply_list; /* regulators we supply */ | ||
172 | |||
173 | struct blocking_notifier_head notifier; | ||
174 | struct mutex mutex; /* consumer lock */ | ||
175 | struct module *owner; | ||
176 | struct device dev; | ||
177 | struct regulation_constraints *constraints; | ||
178 | struct regulator_dev *supply; /* for tree */ | ||
179 | |||
180 | void *reg_data; /* regulator_dev data */ | ||
181 | }; | ||
182 | |||
123 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | 183 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, |
124 | struct device *dev, void *driver_data); | 184 | struct device *dev, struct regulator_init_data *init_data, |
185 | void *driver_data); | ||
125 | void regulator_unregister(struct regulator_dev *rdev); | 186 | void regulator_unregister(struct regulator_dev *rdev); |
126 | 187 | ||
127 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | 188 | int regulator_notifier_call_chain(struct regulator_dev *rdev, |
diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h index 1387a5d2190e..91b4da31f1b5 100644 --- a/include/linux/regulator/fixed.h +++ b/include/linux/regulator/fixed.h | |||
@@ -14,9 +14,12 @@ | |||
14 | #ifndef __REGULATOR_FIXED_H | 14 | #ifndef __REGULATOR_FIXED_H |
15 | #define __REGULATOR_FIXED_H | 15 | #define __REGULATOR_FIXED_H |
16 | 16 | ||
17 | struct regulator_init_data; | ||
18 | |||
17 | struct fixed_voltage_config { | 19 | struct fixed_voltage_config { |
18 | const char *supply_name; | 20 | const char *supply_name; |
19 | int microvolts; | 21 | int microvolts; |
22 | struct regulator_init_data *init_data; | ||
20 | }; | 23 | }; |
21 | 24 | ||
22 | #endif | 25 | #endif |
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index 3794773b23d2..bac64fa390f2 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | 4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. |
5 | * | 5 | * |
6 | * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | 6 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 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 | 9 | * it under the terms of the GNU General Public License version 2 as |
@@ -73,7 +73,9 @@ struct regulator_state { | |||
73 | * | 73 | * |
74 | * @always_on: Set if the regulator should never be disabled. | 74 | * @always_on: Set if the regulator should never be disabled. |
75 | * @boot_on: Set if the regulator is enabled when the system is initially | 75 | * @boot_on: Set if the regulator is enabled when the system is initially |
76 | * started. | 76 | * started. If the regulator is not enabled by the hardware or |
77 | * bootloader then it will be enabled when the constraints are | ||
78 | * applied. | ||
77 | * @apply_uV: Apply the voltage constraint when initialising. | 79 | * @apply_uV: Apply the voltage constraint when initialising. |
78 | * | 80 | * |
79 | * @input_uV: Input voltage for regulator when supplied by another regulator. | 81 | * @input_uV: Input voltage for regulator when supplied by another regulator. |
@@ -83,6 +85,7 @@ struct regulator_state { | |||
83 | * @state_standby: State for regulator when system is suspended in standby | 85 | * @state_standby: State for regulator when system is suspended in standby |
84 | * mode. | 86 | * mode. |
85 | * @initial_state: Suspend state to set by default. | 87 | * @initial_state: Suspend state to set by default. |
88 | * @initial_mode: Mode to set at startup. | ||
86 | */ | 89 | */ |
87 | struct regulation_constraints { | 90 | struct regulation_constraints { |
88 | 91 | ||
@@ -111,6 +114,9 @@ struct regulation_constraints { | |||
111 | struct regulator_state state_standby; | 114 | struct regulator_state state_standby; |
112 | suspend_state_t initial_state; /* suspend state to set at init */ | 115 | suspend_state_t initial_state; /* suspend state to set at init */ |
113 | 116 | ||
117 | /* mode to set on startup */ | ||
118 | unsigned int initial_mode; | ||
119 | |||
114 | /* constriant flags */ | 120 | /* constriant flags */ |
115 | unsigned always_on:1; /* regulator never off when system is on */ | 121 | unsigned always_on:1; /* regulator never off when system is on */ |
116 | unsigned boot_on:1; /* bootloader/firmware enabled regulator */ | 122 | unsigned boot_on:1; /* bootloader/firmware enabled regulator */ |
@@ -160,4 +166,6 @@ struct regulator_init_data { | |||
160 | 166 | ||
161 | int regulator_suspend_prepare(suspend_state_t state); | 167 | int regulator_suspend_prepare(suspend_state_t state); |
162 | 168 | ||
169 | void regulator_has_full_constraints(void); | ||
170 | |||
163 | #endif | 171 | #endif |