diff options
-rw-r--r-- | Documentation/devicetree/bindings/regulator/regulator.txt | 54 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 1 | ||||
-rw-r--r-- | drivers/regulator/of_regulator.c | 81 | ||||
-rw-r--r-- | include/linux/regulator/of_regulator.h | 20 |
4 files changed, 156 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt new file mode 100644 index 000000000000..82bef20d4c49 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/regulator.txt | |||
@@ -0,0 +1,54 @@ | |||
1 | Voltage/Current Regulators | ||
2 | |||
3 | Optional properties: | ||
4 | - regulator-name: A string used as a descriptive name for regulator outputs | ||
5 | - regulator-min-microvolt: smallest voltage consumers may set | ||
6 | - regulator-max-microvolt: largest voltage consumers may set | ||
7 | - regulator-microvolt-offset: Offset applied to voltages to compensate for voltage drops | ||
8 | - regulator-min-microamp: smallest current consumers may set | ||
9 | - regulator-max-microamp: largest current consumers may set | ||
10 | - regulator-always-on: boolean, regulator should never be disabled | ||
11 | - regulator-boot-on: bootloader/firmware enabled regulator | ||
12 | - <name>-supply: phandle to the parent supply/regulator node | ||
13 | |||
14 | Example: | ||
15 | |||
16 | xyzreg: regulator@0 { | ||
17 | regulator-min-microvolt = <1000000>; | ||
18 | regulator-max-microvolt = <2500000>; | ||
19 | regulator-always-on; | ||
20 | vin-supply = <&vin>; | ||
21 | }; | ||
22 | |||
23 | Regulator Consumers: | ||
24 | Consumer nodes can reference one or more of its supplies/ | ||
25 | regulators using the below bindings. | ||
26 | |||
27 | - <name>-supply: phandle to the regulator node | ||
28 | |||
29 | These are the same bindings that a regulator in the above | ||
30 | example used to reference its own supply, in which case | ||
31 | its just seen as a special case of a regulator being a | ||
32 | consumer itself. | ||
33 | |||
34 | Example of a consumer device node (mmc) referencing two | ||
35 | regulators (twl-reg1 and twl-reg2), | ||
36 | |||
37 | twl-reg1: regulator@0 { | ||
38 | ... | ||
39 | ... | ||
40 | ... | ||
41 | }; | ||
42 | |||
43 | twl-reg2: regulator@1 { | ||
44 | ... | ||
45 | ... | ||
46 | ... | ||
47 | }; | ||
48 | |||
49 | mmc: mmc@0x0 { | ||
50 | ... | ||
51 | ... | ||
52 | vmmc-supply = <&twl-reg1>; | ||
53 | vmmcaux-supply = <&twl-reg2>; | ||
54 | }; | ||
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 93a6318f5328..c75a5229cb27 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | 5 | ||
6 | obj-$(CONFIG_REGULATOR) += core.o dummy.o | 6 | obj-$(CONFIG_REGULATOR) += core.o dummy.o |
7 | obj-$(CONFIG_OF) += of_regulator.o | ||
7 | obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o | 8 | obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o |
8 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o | 9 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o |
9 | obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o | 10 | obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o |
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c new file mode 100644 index 000000000000..76673c784ab8 --- /dev/null +++ b/drivers/regulator/of_regulator.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | * OF helpers for regulator framework | ||
3 | * | ||
4 | * Copyright (C) 2011 Texas Instruments, Inc. | ||
5 | * Rajendra Nayak <rnayak@ti.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | */ | ||
12 | |||
13 | #include <linux/slab.h> | ||
14 | #include <linux/of.h> | ||
15 | #include <linux/regulator/machine.h> | ||
16 | |||
17 | static void of_get_regulation_constraints(struct device_node *np, | ||
18 | struct regulator_init_data **init_data) | ||
19 | { | ||
20 | const __be32 *min_uV, *max_uV, *uV_offset; | ||
21 | const __be32 *min_uA, *max_uA; | ||
22 | struct regulation_constraints *constraints = &(*init_data)->constraints; | ||
23 | |||
24 | constraints->name = of_get_property(np, "regulator-name", NULL); | ||
25 | |||
26 | min_uV = of_get_property(np, "regulator-min-microvolt", NULL); | ||
27 | if (min_uV) | ||
28 | constraints->min_uV = be32_to_cpu(*min_uV); | ||
29 | max_uV = of_get_property(np, "regulator-max-microvolt", NULL); | ||
30 | if (max_uV) | ||
31 | constraints->max_uV = be32_to_cpu(*max_uV); | ||
32 | |||
33 | /* Voltage change possible? */ | ||
34 | if (constraints->min_uV != constraints->max_uV) | ||
35 | constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE; | ||
36 | |||
37 | uV_offset = of_get_property(np, "regulator-microvolt-offset", NULL); | ||
38 | if (uV_offset) | ||
39 | constraints->uV_offset = be32_to_cpu(*uV_offset); | ||
40 | min_uA = of_get_property(np, "regulator-min-microamp", NULL); | ||
41 | if (min_uA) | ||
42 | constraints->min_uA = be32_to_cpu(*min_uA); | ||
43 | max_uA = of_get_property(np, "regulator-max-microamp", NULL); | ||
44 | if (max_uA) | ||
45 | constraints->max_uA = be32_to_cpu(*max_uA); | ||
46 | |||
47 | /* Current change possible? */ | ||
48 | if (constraints->min_uA != constraints->max_uA) | ||
49 | constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT; | ||
50 | |||
51 | if (of_find_property(np, "regulator-boot-on", NULL)) | ||
52 | constraints->boot_on = true; | ||
53 | |||
54 | if (of_find_property(np, "regulator-always-on", NULL)) | ||
55 | constraints->always_on = true; | ||
56 | else /* status change should be possible if not always on. */ | ||
57 | constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * of_get_regulator_init_data - extract regulator_init_data structure info | ||
62 | * @dev: device requesting for regulator_init_data | ||
63 | * | ||
64 | * Populates regulator_init_data structure by extracting data from device | ||
65 | * tree node, returns a pointer to the populated struture or NULL if memory | ||
66 | * alloc fails. | ||
67 | */ | ||
68 | struct regulator_init_data *of_get_regulator_init_data(struct device *dev) | ||
69 | { | ||
70 | struct regulator_init_data *init_data; | ||
71 | |||
72 | if (!dev->of_node) | ||
73 | return NULL; | ||
74 | |||
75 | init_data = devm_kzalloc(dev, sizeof(*init_data), GFP_KERNEL); | ||
76 | if (!init_data) | ||
77 | return NULL; /* Out of memory? */ | ||
78 | |||
79 | of_get_regulation_constraints(dev->of_node, &init_data); | ||
80 | return init_data; | ||
81 | } | ||
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h new file mode 100644 index 000000000000..d83a98d3e3fd --- /dev/null +++ b/include/linux/regulator/of_regulator.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* | ||
2 | * OpenFirmware regulator support routines | ||
3 | * | ||
4 | */ | ||
5 | |||
6 | #ifndef __LINUX_OF_REG_H | ||
7 | #define __LINUX_OF_REG_H | ||
8 | |||
9 | #if defined(CONFIG_OF) | ||
10 | extern struct regulator_init_data | ||
11 | *of_get_regulator_init_data(struct device *dev); | ||
12 | #else | ||
13 | static inline struct regulator_init_data | ||
14 | *of_get_regulator_init_data(struct device *dev) | ||
15 | { | ||
16 | return NULL; | ||
17 | } | ||
18 | #endif /* CONFIG_OF */ | ||
19 | |||
20 | #endif /* __LINUX_OF_REG_H */ | ||