diff options
-rw-r--r-- | Documentation/ABI/testing/sysfs-class-regulator | 57 | ||||
-rw-r--r-- | drivers/regulator/core.c | 46 | ||||
-rw-r--r-- | include/linux/regulator/driver.h | 17 |
3 files changed, 111 insertions, 9 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/drivers/regulator/core.c b/drivers/regulator/core.c index f511a406fcaa..0ff95c3ccf5b 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -312,6 +312,47 @@ static ssize_t regulator_state_show(struct device *dev, | |||
312 | } | 312 | } |
313 | static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); | 313 | static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); |
314 | 314 | ||
315 | static ssize_t regulator_status_show(struct device *dev, | ||
316 | struct device_attribute *attr, char *buf) | ||
317 | { | ||
318 | struct regulator_dev *rdev = dev_get_drvdata(dev); | ||
319 | int status; | ||
320 | char *label; | ||
321 | |||
322 | status = rdev->desc->ops->get_status(rdev); | ||
323 | if (status < 0) | ||
324 | return status; | ||
325 | |||
326 | switch (status) { | ||
327 | case REGULATOR_STATUS_OFF: | ||
328 | label = "off"; | ||
329 | break; | ||
330 | case REGULATOR_STATUS_ON: | ||
331 | label = "on"; | ||
332 | break; | ||
333 | case REGULATOR_STATUS_ERROR: | ||
334 | label = "error"; | ||
335 | break; | ||
336 | case REGULATOR_STATUS_FAST: | ||
337 | label = "fast"; | ||
338 | break; | ||
339 | case REGULATOR_STATUS_NORMAL: | ||
340 | label = "normal"; | ||
341 | break; | ||
342 | case REGULATOR_STATUS_IDLE: | ||
343 | label = "idle"; | ||
344 | break; | ||
345 | case REGULATOR_STATUS_STANDBY: | ||
346 | label = "standby"; | ||
347 | break; | ||
348 | default: | ||
349 | return -ERANGE; | ||
350 | } | ||
351 | |||
352 | return sprintf(buf, "%s\n", label); | ||
353 | } | ||
354 | static DEVICE_ATTR(status, 0444, regulator_status_show, NULL); | ||
355 | |||
315 | static ssize_t regulator_min_uA_show(struct device *dev, | 356 | static ssize_t regulator_min_uA_show(struct device *dev, |
316 | struct device_attribute *attr, char *buf) | 357 | struct device_attribute *attr, char *buf) |
317 | { | 358 | { |
@@ -1744,6 +1785,11 @@ static int add_regulator_attributes(struct regulator_dev *rdev) | |||
1744 | if (status < 0) | 1785 | if (status < 0) |
1745 | return status; | 1786 | return status; |
1746 | } | 1787 | } |
1788 | if (ops->get_status) { | ||
1789 | status = device_create_file(dev, &dev_attr_status); | ||
1790 | if (status < 0) | ||
1791 | return status; | ||
1792 | } | ||
1747 | 1793 | ||
1748 | /* some attributes are type-specific */ | 1794 | /* some attributes are type-specific */ |
1749 | if (rdev->desc->type == REGULATOR_CURRENT) { | 1795 | if (rdev->desc->type == REGULATOR_CURRENT) { |
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 2dae05705f13..6e957aae7629 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h | |||
@@ -21,6 +21,17 @@ | |||
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 | * |
@@ -72,6 +83,12 @@ struct regulator_ops { | |||
72 | int (*set_mode) (struct regulator_dev *, unsigned int mode); | 83 | int (*set_mode) (struct regulator_dev *, unsigned int mode); |
73 | unsigned int (*get_mode) (struct regulator_dev *); | 84 | unsigned int (*get_mode) (struct regulator_dev *); |
74 | 85 | ||
86 | /* report regulator status ... most other accessors report | ||
87 | * control inputs, this reports results of combining inputs | ||
88 | * from Linux (and other sources) with the actual load. | ||
89 | */ | ||
90 | int (*get_status)(struct regulator_dev *); | ||
91 | |||
75 | /* get most efficient regulator operating mode for load */ | 92 | /* get most efficient regulator operating mode for load */ |
76 | unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, | 93 | unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, |
77 | int output_uV, int load_uA); | 94 | int output_uV, int load_uA); |