aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2008-11-11 20:39:02 -0500
committerLiam Girdwood <lrg@slimlogic.co.uk>2009-01-08 15:10:30 -0500
commit7ad68e2f970fd84d15ad67ce3216aed05f944a9c (patch)
treeb7bb5f33e6a6a1d60cc9d2be24a7d2dee36f0f93
parent4fca9545d17b99cdb2774716b034c62a70151bcd (diff)
regulator: sysfs attribute reduction (v2)
Clean up the sysfs interface to regulators by only exposing the attributes that can be properly displayed. For example: when a particular regulator method is needed to display the value, only create that attribute when that method exists. This cleaned-up interface is much more comprehensible. Most regulators only support a subset of the possible methods, so often more than half the attributes would be meaningless. Many "not defined" values are no longer necessary. (But handling of out-of-range values still looks a bit iffy.) Documentation is updated to reflect that few of the attributes are *always* present, and to briefly explain why a regulator may not have a given attribute. This adds object code, about a dozen bytes more than was removed by the preceding patch, but saves a bunch of per-regulator data associated with the now-removed attributes. So there's a net reduction in memory footprint. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
-rw-r--r--Documentation/ABI/testing/sysfs-class-regulator136
-rw-r--r--drivers/regulator/core.c196
2 files changed, 208 insertions, 124 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-regulator b/Documentation/ABI/testing/sysfs-class-regulator
index 3731f6f29bcb..873ef1fc1569 100644
--- a/Documentation/ABI/testing/sysfs-class-regulator
+++ b/Documentation/ABI/testing/sysfs-class-regulator
@@ -3,8 +3,9 @@ Date: April 2008
3KernelVersion: 2.6.26 3KernelVersion: 2.6.26
4Contact: Liam Girdwood <lrg@slimlogic.co.uk> 4Contact: Liam Girdwood <lrg@slimlogic.co.uk>
5Description: 5Description:
6 Each regulator directory will contain a field called 6 Some regulator directories will contain a field called
7 state. This holds the regulator output state. 7 state. This reports the regulator enable status, for
8 regulators which can report that value.
8 9
9 This will be one of the following strings: 10 This will be one of the following strings:
10 11
@@ -18,7 +19,8 @@ Description:
18 'disabled' means the regulator output is OFF and is not 19 'disabled' means the regulator output is OFF and is not
19 supplying power to the system.. 20 supplying power to the system..
20 21
21 'unknown' means software cannot determine the state. 22 'unknown' means software cannot determine the state, or
23 the reported state is invalid.
22 24
23 NOTE: this field can be used in conjunction with microvolts 25 NOTE: this field can be used in conjunction with microvolts
24 and microamps to determine regulator output levels. 26 and microamps to determine regulator output levels.
@@ -53,9 +55,10 @@ Date: April 2008
53KernelVersion: 2.6.26 55KernelVersion: 2.6.26
54Contact: Liam Girdwood <lrg@slimlogic.co.uk> 56Contact: Liam Girdwood <lrg@slimlogic.co.uk>
55Description: 57Description:
56 Each regulator directory will contain a field called 58 Some regulator directories will contain a field called
57 microvolts. This holds the regulator output voltage setting 59 microvolts. This holds the regulator output voltage setting
58 measured in microvolts (i.e. E-6 Volts). 60 measured in microvolts (i.e. E-6 Volts), for regulators
61 which can report that voltage.
59 62
60 NOTE: This value should not be used to determine the regulator 63 NOTE: This value should not be used to determine the regulator
61 output voltage level as this value is the same regardless of 64 output voltage level as this value is the same regardless of
@@ -67,9 +70,10 @@ Date: April 2008
67KernelVersion: 2.6.26 70KernelVersion: 2.6.26
68Contact: Liam Girdwood <lrg@slimlogic.co.uk> 71Contact: Liam Girdwood <lrg@slimlogic.co.uk>
69Description: 72Description:
70 Each regulator directory will contain a field called 73 Some regulator directories will contain a field called
71 microamps. This holds the regulator output current limit 74 microamps. This holds the regulator output current limit
72 setting measured in microamps (i.e. E-6 Amps). 75 setting measured in microamps (i.e. E-6 Amps), for regulators
76 which can report that current.
73 77
74 NOTE: This value should not be used to determine the regulator 78 NOTE: This value should not be used to determine the regulator
75 output current level as this value is the same regardless of 79 output current level as this value is the same regardless of
@@ -81,8 +85,9 @@ Date: April 2008
81KernelVersion: 2.6.26 85KernelVersion: 2.6.26
82Contact: Liam Girdwood <lrg@slimlogic.co.uk> 86Contact: Liam Girdwood <lrg@slimlogic.co.uk>
83Description: 87Description:
84 Each regulator directory will contain a field called 88 Some regulator directories will contain a field called
85 opmode. This holds the regulator operating mode setting. 89 opmode. This holds the current regulator operating mode,
90 for regulators which can report it.
86 91
87 The opmode value can be one of the following strings: 92 The opmode value can be one of the following strings:
88 93
@@ -92,7 +97,7 @@ Description:
92 'standby' 97 'standby'
93 'unknown' 98 'unknown'
94 99
95 The modes are described in include/linux/regulator/regulator.h 100 The modes are described in include/linux/regulator/consumer.h
96 101
97 NOTE: This value should not be used to determine the regulator 102 NOTE: This value should not be used to determine the regulator
98 output operating mode as this value is the same regardless of 103 output operating mode as this value is the same regardless of
@@ -104,9 +109,10 @@ Date: April 2008
104KernelVersion: 2.6.26 109KernelVersion: 2.6.26
105Contact: Liam Girdwood <lrg@slimlogic.co.uk> 110Contact: Liam Girdwood <lrg@slimlogic.co.uk>
106Description: 111Description:
107 Each regulator directory will contain a field called 112 Some regulator directories will contain a field called
108 min_microvolts. This holds the minimum safe working regulator 113 min_microvolts. This holds the minimum safe working regulator
109 output voltage setting for this domain measured in microvolts. 114 output voltage setting for this domain measured in microvolts,
115 for regulators which support voltage constraints.
110 116
111 NOTE: this will return the string 'constraint not defined' if 117 NOTE: this will return the string 'constraint not defined' if
112 the power domain has no min microvolts constraint defined by 118 the power domain has no min microvolts constraint defined by
@@ -118,9 +124,10 @@ Date: April 2008
118KernelVersion: 2.6.26 124KernelVersion: 2.6.26
119Contact: Liam Girdwood <lrg@slimlogic.co.uk> 125Contact: Liam Girdwood <lrg@slimlogic.co.uk>
120Description: 126Description:
121 Each regulator directory will contain a field called 127 Some regulator directories will contain a field called
122 max_microvolts. This holds the maximum safe working regulator 128 max_microvolts. This holds the maximum safe working regulator
123 output voltage setting for this domain measured in microvolts. 129 output voltage setting for this domain measured in microvolts,
130 for regulators which support voltage constraints.
124 131
125 NOTE: this will return the string 'constraint not defined' if 132 NOTE: this will return the string 'constraint not defined' if
126 the power domain has no max microvolts constraint defined by 133 the power domain has no max microvolts constraint defined by
@@ -132,10 +139,10 @@ Date: April 2008
132KernelVersion: 2.6.26 139KernelVersion: 2.6.26
133Contact: Liam Girdwood <lrg@slimlogic.co.uk> 140Contact: Liam Girdwood <lrg@slimlogic.co.uk>
134Description: 141Description:
135 Each regulator directory will contain a field called 142 Some regulator directories will contain a field called
136 min_microamps. This holds the minimum safe working regulator 143 min_microamps. This holds the minimum safe working regulator
137 output current limit setting for this domain measured in 144 output current limit setting for this domain measured in
138 microamps. 145 microamps, for regulators which support current constraints.
139 146
140 NOTE: this will return the string 'constraint not defined' if 147 NOTE: this will return the string 'constraint not defined' if
141 the power domain has no min microamps constraint defined by 148 the power domain has no min microamps constraint defined by
@@ -147,10 +154,10 @@ Date: April 2008
147KernelVersion: 2.6.26 154KernelVersion: 2.6.26
148Contact: Liam Girdwood <lrg@slimlogic.co.uk> 155Contact: Liam Girdwood <lrg@slimlogic.co.uk>
149Description: 156Description:
150 Each regulator directory will contain a field called 157 Some regulator directories will contain a field called
151 max_microamps. This holds the maximum safe working regulator 158 max_microamps. This holds the maximum safe working regulator
152 output current limit setting for this domain measured in 159 output current limit setting for this domain measured in
153 microamps. 160 microamps, for regulators which support current constraints.
154 161
155 NOTE: this will return the string 'constraint not defined' if 162 NOTE: this will return the string 'constraint not defined' if
156 the power domain has no max microamps constraint defined by 163 the power domain has no max microamps constraint defined by
@@ -185,7 +192,7 @@ Date: April 2008
185KernelVersion: 2.6.26 192KernelVersion: 2.6.26
186Contact: Liam Girdwood <lrg@slimlogic.co.uk> 193Contact: Liam Girdwood <lrg@slimlogic.co.uk>
187Description: 194Description:
188 Each regulator directory will contain a field called 195 Some regulator directories will contain a field called
189 requested_microamps. This holds the total requested load 196 requested_microamps. This holds the total requested load
190 current in microamps for this regulator from all its consumer 197 current in microamps for this regulator from all its consumer
191 devices. 198 devices.
@@ -204,125 +211,102 @@ Date: May 2008
204KernelVersion: 2.6.26 211KernelVersion: 2.6.26
205Contact: Liam Girdwood <lrg@slimlogic.co.uk> 212Contact: Liam Girdwood <lrg@slimlogic.co.uk>
206Description: 213Description:
207 Each regulator directory will contain a field called 214 Some regulator directories will contain a field called
208 suspend_mem_microvolts. This holds the regulator output 215 suspend_mem_microvolts. This holds the regulator output
209 voltage setting for this domain measured in microvolts when 216 voltage setting for this domain measured in microvolts when
210 the system is suspended to memory. 217 the system is suspended to memory, for voltage regulators
211 218 implementing suspend voltage configuration constraints.
212 NOTE: this will return the string 'not defined' if
213 the power domain has no suspend to memory voltage defined by
214 platform code.
215 219
216What: /sys/class/regulator/.../suspend_disk_microvolts 220What: /sys/class/regulator/.../suspend_disk_microvolts
217Date: May 2008 221Date: May 2008
218KernelVersion: 2.6.26 222KernelVersion: 2.6.26
219Contact: Liam Girdwood <lrg@slimlogic.co.uk> 223Contact: Liam Girdwood <lrg@slimlogic.co.uk>
220Description: 224Description:
221 Each regulator directory will contain a field called 225 Some regulator directories will contain a field called
222 suspend_disk_microvolts. This holds the regulator output 226 suspend_disk_microvolts. This holds the regulator output
223 voltage setting for this domain measured in microvolts when 227 voltage setting for this domain measured in microvolts when
224 the system is suspended to disk. 228 the system is suspended to disk, for voltage regulators
225 229 implementing suspend voltage configuration constraints.
226 NOTE: this will return the string 'not defined' if
227 the power domain has no suspend to disk voltage defined by
228 platform code.
229 230
230What: /sys/class/regulator/.../suspend_standby_microvolts 231What: /sys/class/regulator/.../suspend_standby_microvolts
231Date: May 2008 232Date: May 2008
232KernelVersion: 2.6.26 233KernelVersion: 2.6.26
233Contact: Liam Girdwood <lrg@slimlogic.co.uk> 234Contact: Liam Girdwood <lrg@slimlogic.co.uk>
234Description: 235Description:
235 Each regulator directory will contain a field called 236 Some regulator directories will contain a field called
236 suspend_standby_microvolts. This holds the regulator output 237 suspend_standby_microvolts. This holds the regulator output
237 voltage setting for this domain measured in microvolts when 238 voltage setting for this domain measured in microvolts when
238 the system is suspended to standby. 239 the system is suspended to standby, for voltage regulators
239 240 implementing suspend voltage configuration constraints.
240 NOTE: this will return the string 'not defined' if
241 the power domain has no suspend to standby voltage defined by
242 platform code.
243 241
244What: /sys/class/regulator/.../suspend_mem_mode 242What: /sys/class/regulator/.../suspend_mem_mode
245Date: May 2008 243Date: May 2008
246KernelVersion: 2.6.26 244KernelVersion: 2.6.26
247Contact: Liam Girdwood <lrg@slimlogic.co.uk> 245Contact: Liam Girdwood <lrg@slimlogic.co.uk>
248Description: 246Description:
249 Each regulator directory will contain a field called 247 Some regulator directories will contain a field called
250 suspend_mem_mode. This holds the regulator operating mode 248 suspend_mem_mode. This holds the regulator operating mode
251 setting for this domain when the system is suspended to 249 setting for this domain when the system is suspended to
252 memory. 250 memory, for regulators implementing suspend mode
253 251 configuration constraints.
254 NOTE: this will return the string 'not defined' if
255 the power domain has no suspend to memory mode defined by
256 platform code.
257 252
258What: /sys/class/regulator/.../suspend_disk_mode 253What: /sys/class/regulator/.../suspend_disk_mode
259Date: May 2008 254Date: May 2008
260KernelVersion: 2.6.26 255KernelVersion: 2.6.26
261Contact: Liam Girdwood <lrg@slimlogic.co.uk> 256Contact: Liam Girdwood <lrg@slimlogic.co.uk>
262Description: 257Description:
263 Each regulator directory will contain a field called 258 Some regulator directories will contain a field called
264 suspend_disk_mode. This holds the regulator operating mode 259 suspend_disk_mode. This holds the regulator operating mode
265 setting for this domain when the system is suspended to disk. 260 setting for this domain when the system is suspended to disk,
266 261 for regulators implementing suspend mode configuration
267 NOTE: this will return the string 'not defined' if 262 constraints.
268 the power domain has no suspend to disk mode defined by
269 platform code.
270 263
271What: /sys/class/regulator/.../suspend_standby_mode 264What: /sys/class/regulator/.../suspend_standby_mode
272Date: May 2008 265Date: May 2008
273KernelVersion: 2.6.26 266KernelVersion: 2.6.26
274Contact: Liam Girdwood <lrg@slimlogic.co.uk> 267Contact: Liam Girdwood <lrg@slimlogic.co.uk>
275Description: 268Description:
276 Each regulator directory will contain a field called 269 Some regulator directories will contain a field called
277 suspend_standby_mode. This holds the regulator operating mode 270 suspend_standby_mode. This holds the regulator operating mode
278 setting for this domain when the system is suspended to 271 setting for this domain when the system is suspended to
279 standby. 272 standby, for regulators implementing suspend mode
280 273 configuration constraints.
281 NOTE: this will return the string 'not defined' if
282 the power domain has no suspend to standby mode defined by
283 platform code.
284 274
285What: /sys/class/regulator/.../suspend_mem_state 275What: /sys/class/regulator/.../suspend_mem_state
286Date: May 2008 276Date: May 2008
287KernelVersion: 2.6.26 277KernelVersion: 2.6.26
288Contact: Liam Girdwood <lrg@slimlogic.co.uk> 278Contact: Liam Girdwood <lrg@slimlogic.co.uk>
289Description: 279Description:
290 Each regulator directory will contain a field called 280 Some regulator directories will contain a field called
291 suspend_mem_state. This holds the regulator operating state 281 suspend_mem_state. This holds the regulator operating state
292 when suspended to memory. 282 when suspended to memory, for regulators implementing suspend
293 283 configuration constraints.
294 This will be one of the following strings:
295 284
296 'enabled' 285 This will be one of the same strings reported by
297 'disabled' 286 the "state" attribute.
298 'not defined'
299 287
300What: /sys/class/regulator/.../suspend_disk_state 288What: /sys/class/regulator/.../suspend_disk_state
301Date: May 2008 289Date: May 2008
302KernelVersion: 2.6.26 290KernelVersion: 2.6.26
303Contact: Liam Girdwood <lrg@slimlogic.co.uk> 291Contact: Liam Girdwood <lrg@slimlogic.co.uk>
304Description: 292Description:
305 Each regulator directory will contain a field called 293 Some regulator directories will contain a field called
306 suspend_disk_state. This holds the regulator operating state 294 suspend_disk_state. This holds the regulator operating state
307 when suspended to disk. 295 when suspended to disk, for regulators implementing
308 296 suspend configuration constraints.
309 This will be one of the following strings:
310 297
311 'enabled' 298 This will be one of the same strings reported by
312 'disabled' 299 the "state" attribute.
313 'not defined'
314 300
315What: /sys/class/regulator/.../suspend_standby_state 301What: /sys/class/regulator/.../suspend_standby_state
316Date: May 2008 302Date: May 2008
317KernelVersion: 2.6.26 303KernelVersion: 2.6.26
318Contact: Liam Girdwood <lrg@slimlogic.co.uk> 304Contact: Liam Girdwood <lrg@slimlogic.co.uk>
319Description: 305Description:
320 Each regulator directory will contain a field called 306 Some regulator directories will contain a field called
321 suspend_standby_state. This holds the regulator operating 307 suspend_standby_state. This holds the regulator operating
322 state when suspended to standby. 308 state when suspended to standby, for regulators implementing
323 309 suspend configuration constraints.
324 This will be one of the following strings:
325 310
326 'enabled' 311 This will be one of the same strings reported by
327 'disabled' 312 the "state" attribute.
328 'not defined'
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 5109f7d4809a..9a5ff97d158d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -242,6 +242,7 @@ static ssize_t regulator_uV_show(struct device *dev,
242 242
243 return ret; 243 return ret;
244} 244}
245static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
245 246
246static ssize_t regulator_uA_show(struct device *dev, 247static ssize_t regulator_uA_show(struct device *dev,
247 struct device_attribute *attr, char *buf) 248 struct device_attribute *attr, char *buf)
@@ -250,6 +251,7 @@ static ssize_t regulator_uA_show(struct device *dev,
250 251
251 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); 252 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
252} 253}
254static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL);
253 255
254static ssize_t regulator_name_show(struct device *dev, 256static ssize_t regulator_name_show(struct device *dev,
255 struct device_attribute *attr, char *buf) 257 struct device_attribute *attr, char *buf)
@@ -289,6 +291,7 @@ static ssize_t regulator_opmode_show(struct device *dev,
289 291
290 return regulator_print_opmode(buf, _regulator_get_mode(rdev)); 292 return regulator_print_opmode(buf, _regulator_get_mode(rdev));
291} 293}
294static DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL);
292 295
293static ssize_t regulator_print_state(char *buf, int state) 296static ssize_t regulator_print_state(char *buf, int state)
294{ 297{
@@ -307,6 +310,7 @@ static ssize_t regulator_state_show(struct device *dev,
307 310
308 return regulator_print_state(buf, _regulator_is_enabled(rdev)); 311 return regulator_print_state(buf, _regulator_is_enabled(rdev));
309} 312}
313static DEVICE_ATTR(state, 0444, regulator_state_show, NULL);
310 314
311static ssize_t regulator_min_uA_show(struct device *dev, 315static ssize_t regulator_min_uA_show(struct device *dev,
312 struct device_attribute *attr, char *buf) 316 struct device_attribute *attr, char *buf)
@@ -318,6 +322,7 @@ static ssize_t regulator_min_uA_show(struct device *dev,
318 322
319 return sprintf(buf, "%d\n", rdev->constraints->min_uA); 323 return sprintf(buf, "%d\n", rdev->constraints->min_uA);
320} 324}
325static DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL);
321 326
322static ssize_t regulator_max_uA_show(struct device *dev, 327static ssize_t regulator_max_uA_show(struct device *dev,
323 struct device_attribute *attr, char *buf) 328 struct device_attribute *attr, char *buf)
@@ -329,6 +334,7 @@ static ssize_t regulator_max_uA_show(struct device *dev,
329 334
330 return sprintf(buf, "%d\n", rdev->constraints->max_uA); 335 return sprintf(buf, "%d\n", rdev->constraints->max_uA);
331} 336}
337static DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL);
332 338
333static ssize_t regulator_min_uV_show(struct device *dev, 339static ssize_t regulator_min_uV_show(struct device *dev,
334 struct device_attribute *attr, char *buf) 340 struct device_attribute *attr, char *buf)
@@ -340,6 +346,7 @@ static ssize_t regulator_min_uV_show(struct device *dev,
340 346
341 return sprintf(buf, "%d\n", rdev->constraints->min_uV); 347 return sprintf(buf, "%d\n", rdev->constraints->min_uV);
342} 348}
349static DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL);
343 350
344static ssize_t regulator_max_uV_show(struct device *dev, 351static ssize_t regulator_max_uV_show(struct device *dev,
345 struct device_attribute *attr, char *buf) 352 struct device_attribute *attr, char *buf)
@@ -351,6 +358,7 @@ static ssize_t regulator_max_uV_show(struct device *dev,
351 358
352 return sprintf(buf, "%d\n", rdev->constraints->max_uV); 359 return sprintf(buf, "%d\n", rdev->constraints->max_uV);
353} 360}
361static DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL);
354 362
355static ssize_t regulator_total_uA_show(struct device *dev, 363static ssize_t regulator_total_uA_show(struct device *dev,
356 struct device_attribute *attr, char *buf) 364 struct device_attribute *attr, char *buf)
@@ -365,6 +373,7 @@ static ssize_t regulator_total_uA_show(struct device *dev,
365 mutex_unlock(&rdev->mutex); 373 mutex_unlock(&rdev->mutex);
366 return sprintf(buf, "%d\n", uA); 374 return sprintf(buf, "%d\n", uA);
367} 375}
376static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL);
368 377
369static ssize_t regulator_num_users_show(struct device *dev, 378static ssize_t regulator_num_users_show(struct device *dev,
370 struct device_attribute *attr, char *buf) 379 struct device_attribute *attr, char *buf)
@@ -392,131 +401,106 @@ static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
392{ 401{
393 struct regulator_dev *rdev = dev_get_drvdata(dev); 402 struct regulator_dev *rdev = dev_get_drvdata(dev);
394 403
395 if (!rdev->constraints)
396 return sprintf(buf, "not defined\n");
397 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); 404 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV);
398} 405}
406static DEVICE_ATTR(suspend_mem_microvolts, 0444,
407 regulator_suspend_mem_uV_show, NULL);
399 408
400static ssize_t regulator_suspend_disk_uV_show(struct device *dev, 409static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
401 struct device_attribute *attr, char *buf) 410 struct device_attribute *attr, char *buf)
402{ 411{
403 struct regulator_dev *rdev = dev_get_drvdata(dev); 412 struct regulator_dev *rdev = dev_get_drvdata(dev);
404 413
405 if (!rdev->constraints)
406 return sprintf(buf, "not defined\n");
407 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); 414 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV);
408} 415}
416static DEVICE_ATTR(suspend_disk_microvolts, 0444,
417 regulator_suspend_disk_uV_show, NULL);
409 418
410static ssize_t regulator_suspend_standby_uV_show(struct device *dev, 419static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
411 struct device_attribute *attr, char *buf) 420 struct device_attribute *attr, char *buf)
412{ 421{
413 struct regulator_dev *rdev = dev_get_drvdata(dev); 422 struct regulator_dev *rdev = dev_get_drvdata(dev);
414 423
415 if (!rdev->constraints)
416 return sprintf(buf, "not defined\n");
417 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); 424 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV);
418} 425}
426static DEVICE_ATTR(suspend_standby_microvolts, 0444,
427 regulator_suspend_standby_uV_show, NULL);
419 428
420static ssize_t regulator_suspend_mem_mode_show(struct device *dev, 429static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
421 struct device_attribute *attr, char *buf) 430 struct device_attribute *attr, char *buf)
422{ 431{
423 struct regulator_dev *rdev = dev_get_drvdata(dev); 432 struct regulator_dev *rdev = dev_get_drvdata(dev);
424 433
425 if (!rdev->constraints)
426 return sprintf(buf, "not defined\n");
427 return regulator_print_opmode(buf, 434 return regulator_print_opmode(buf,
428 rdev->constraints->state_mem.mode); 435 rdev->constraints->state_mem.mode);
429} 436}
437static DEVICE_ATTR(suspend_mem_mode, 0444,
438 regulator_suspend_mem_mode_show, NULL);
430 439
431static ssize_t regulator_suspend_disk_mode_show(struct device *dev, 440static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
432 struct device_attribute *attr, char *buf) 441 struct device_attribute *attr, char *buf)
433{ 442{
434 struct regulator_dev *rdev = dev_get_drvdata(dev); 443 struct regulator_dev *rdev = dev_get_drvdata(dev);
435 444
436 if (!rdev->constraints)
437 return sprintf(buf, "not defined\n");
438 return regulator_print_opmode(buf, 445 return regulator_print_opmode(buf,
439 rdev->constraints->state_disk.mode); 446 rdev->constraints->state_disk.mode);
440} 447}
448static DEVICE_ATTR(suspend_disk_mode, 0444,
449 regulator_suspend_disk_mode_show, NULL);
441 450
442static ssize_t regulator_suspend_standby_mode_show(struct device *dev, 451static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
443 struct device_attribute *attr, char *buf) 452 struct device_attribute *attr, char *buf)
444{ 453{
445 struct regulator_dev *rdev = dev_get_drvdata(dev); 454 struct regulator_dev *rdev = dev_get_drvdata(dev);
446 455
447 if (!rdev->constraints)
448 return sprintf(buf, "not defined\n");
449 return regulator_print_opmode(buf, 456 return regulator_print_opmode(buf,
450 rdev->constraints->state_standby.mode); 457 rdev->constraints->state_standby.mode);
451} 458}
459static DEVICE_ATTR(suspend_standby_mode, 0444,
460 regulator_suspend_standby_mode_show, NULL);
452 461
453static ssize_t regulator_suspend_mem_state_show(struct device *dev, 462static ssize_t regulator_suspend_mem_state_show(struct device *dev,
454 struct device_attribute *attr, char *buf) 463 struct device_attribute *attr, char *buf)
455{ 464{
456 struct regulator_dev *rdev = dev_get_drvdata(dev); 465 struct regulator_dev *rdev = dev_get_drvdata(dev);
457 466
458 if (!rdev->constraints)
459 return sprintf(buf, "not defined\n");
460
461 return regulator_print_state(buf, 467 return regulator_print_state(buf,
462 rdev->constraints->state_mem.enabled); 468 rdev->constraints->state_mem.enabled);
463} 469}
470static DEVICE_ATTR(suspend_mem_state, 0444,
471 regulator_suspend_mem_state_show, NULL);
464 472
465static ssize_t regulator_suspend_disk_state_show(struct device *dev, 473static ssize_t regulator_suspend_disk_state_show(struct device *dev,
466 struct device_attribute *attr, char *buf) 474 struct device_attribute *attr, char *buf)
467{ 475{
468 struct regulator_dev *rdev = dev_get_drvdata(dev); 476 struct regulator_dev *rdev = dev_get_drvdata(dev);
469 477
470 if (!rdev->constraints)
471 return sprintf(buf, "not defined\n");
472
473 return regulator_print_state(buf, 478 return regulator_print_state(buf,
474 rdev->constraints->state_disk.enabled); 479 rdev->constraints->state_disk.enabled);
475} 480}
481static DEVICE_ATTR(suspend_disk_state, 0444,
482 regulator_suspend_disk_state_show, NULL);
476 483
477static ssize_t regulator_suspend_standby_state_show(struct device *dev, 484static ssize_t regulator_suspend_standby_state_show(struct device *dev,
478 struct device_attribute *attr, char *buf) 485 struct device_attribute *attr, char *buf)
479{ 486{
480 struct regulator_dev *rdev = dev_get_drvdata(dev); 487 struct regulator_dev *rdev = dev_get_drvdata(dev);
481 488
482 if (!rdev->constraints)
483 return sprintf(buf, "not defined\n");
484
485 return regulator_print_state(buf, 489 return regulator_print_state(buf,
486 rdev->constraints->state_standby.enabled); 490 rdev->constraints->state_standby.enabled);
487} 491}
492static DEVICE_ATTR(suspend_standby_state, 0444,
493 regulator_suspend_standby_state_show, NULL);
494
488 495
496/*
497 * These are the only attributes are present for all regulators.
498 * Other attributes are a function of regulator functionality.
499 */
489static struct device_attribute regulator_dev_attrs[] = { 500static struct device_attribute regulator_dev_attrs[] = {
490 __ATTR(name, 0444, regulator_name_show, NULL), 501 __ATTR(name, 0444, regulator_name_show, NULL),
491 __ATTR(microvolts, 0444, regulator_uV_show, NULL),
492 __ATTR(microamps, 0444, regulator_uA_show, NULL),
493 __ATTR(opmode, 0444, regulator_opmode_show, NULL),
494 __ATTR(state, 0444, regulator_state_show, NULL),
495 __ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL),
496 __ATTR(min_microamps, 0444, regulator_min_uA_show, NULL),
497 __ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL),
498 __ATTR(max_microamps, 0444, regulator_max_uA_show, NULL),
499 __ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL),
500 __ATTR(num_users, 0444, regulator_num_users_show, NULL), 502 __ATTR(num_users, 0444, regulator_num_users_show, NULL),
501 __ATTR(type, 0444, regulator_type_show, NULL), 503 __ATTR(type, 0444, regulator_type_show, NULL),
502 __ATTR(suspend_mem_microvolts, 0444,
503 regulator_suspend_mem_uV_show, NULL),
504 __ATTR(suspend_disk_microvolts, 0444,
505 regulator_suspend_disk_uV_show, NULL),
506 __ATTR(suspend_standby_microvolts, 0444,
507 regulator_suspend_standby_uV_show, NULL),
508 __ATTR(suspend_mem_mode, 0444,
509 regulator_suspend_mem_mode_show, NULL),
510 __ATTR(suspend_disk_mode, 0444,
511 regulator_suspend_disk_mode_show, NULL),
512 __ATTR(suspend_standby_mode, 0444,
513 regulator_suspend_standby_mode_show, NULL),
514 __ATTR(suspend_mem_state, 0444,
515 regulator_suspend_mem_state_show, NULL),
516 __ATTR(suspend_disk_state, 0444,
517 regulator_suspend_disk_state_show, NULL),
518 __ATTR(suspend_standby_state, 0444,
519 regulator_suspend_standby_state_show, NULL),
520 __ATTR_NULL, 504 __ATTR_NULL,
521}; 505};
522 506
@@ -1711,6 +1695,117 @@ int regulator_notifier_call_chain(struct regulator_dev *rdev,
1711} 1695}
1712EXPORT_SYMBOL_GPL(regulator_notifier_call_chain); 1696EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
1713 1697
1698/*
1699 * To avoid cluttering sysfs (and memory) with useless state, only
1700 * create attributes that can be meaningfully displayed.
1701 */
1702static int add_regulator_attributes(struct regulator_dev *rdev)
1703{
1704 struct device *dev = &rdev->dev;
1705 struct regulator_ops *ops = rdev->desc->ops;
1706 int status = 0;
1707
1708 /* some attributes need specific methods to be displayed */
1709 if (ops->get_voltage) {
1710 status = device_create_file(dev, &dev_attr_microvolts);
1711 if (status < 0)
1712 return status;
1713 }
1714 if (ops->get_current_limit) {
1715 status = device_create_file(dev, &dev_attr_microamps);
1716 if (status < 0)
1717 return status;
1718 }
1719 if (ops->get_mode) {
1720 status = device_create_file(dev, &dev_attr_opmode);
1721 if (status < 0)
1722 return status;
1723 }
1724 if (ops->is_enabled) {
1725 status = device_create_file(dev, &dev_attr_state);
1726 if (status < 0)
1727 return status;
1728 }
1729
1730 /* some attributes are type-specific */
1731 if (rdev->desc->type == REGULATOR_CURRENT) {
1732 status = device_create_file(dev, &dev_attr_requested_microamps);
1733 if (status < 0)
1734 return status;
1735 }
1736
1737 /* all the other attributes exist to support constraints;
1738 * don't show them if there are no constraints, or if the
1739 * relevant supporting methods are missing.
1740 */
1741 if (!rdev->constraints)
1742 return status;
1743
1744 /* constraints need specific supporting methods */
1745 if (ops->set_voltage) {
1746 status = device_create_file(dev, &dev_attr_min_microvolts);
1747 if (status < 0)
1748 return status;
1749 status = device_create_file(dev, &dev_attr_max_microvolts);
1750 if (status < 0)
1751 return status;
1752 }
1753 if (ops->set_current_limit) {
1754 status = device_create_file(dev, &dev_attr_min_microamps);
1755 if (status < 0)
1756 return status;
1757 status = device_create_file(dev, &dev_attr_max_microamps);
1758 if (status < 0)
1759 return status;
1760 }
1761
1762 /* suspend mode constraints need multiple supporting methods */
1763 if (!(ops->set_suspend_enable && ops->set_suspend_disable))
1764 return status;
1765
1766 status = device_create_file(dev, &dev_attr_suspend_standby_state);
1767 if (status < 0)
1768 return status;
1769 status = device_create_file(dev, &dev_attr_suspend_mem_state);
1770 if (status < 0)
1771 return status;
1772 status = device_create_file(dev, &dev_attr_suspend_disk_state);
1773 if (status < 0)
1774 return status;
1775
1776 if (ops->set_suspend_voltage) {
1777 status = device_create_file(dev,
1778 &dev_attr_suspend_standby_microvolts);
1779 if (status < 0)
1780 return status;
1781 status = device_create_file(dev,
1782 &dev_attr_suspend_mem_microvolts);
1783 if (status < 0)
1784 return status;
1785 status = device_create_file(dev,
1786 &dev_attr_suspend_disk_microvolts);
1787 if (status < 0)
1788 return status;
1789 }
1790
1791 if (ops->set_suspend_mode) {
1792 status = device_create_file(dev,
1793 &dev_attr_suspend_standby_mode);
1794 if (status < 0)
1795 return status;
1796 status = device_create_file(dev,
1797 &dev_attr_suspend_mem_mode);
1798 if (status < 0)
1799 return status;
1800 status = device_create_file(dev,
1801 &dev_attr_suspend_disk_mode);
1802 if (status < 0)
1803 return status;
1804 }
1805
1806 return status;
1807}
1808
1714/** 1809/**
1715 * regulator_register - register regulator 1810 * regulator_register - register regulator
1716 * @regulator: regulator source 1811 * @regulator: regulator source
@@ -1779,6 +1874,11 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1779 1874
1780 dev_set_drvdata(&rdev->dev, rdev); 1875 dev_set_drvdata(&rdev->dev, rdev);
1781 1876
1877 /* add attributes supported by this regulator */
1878 ret = add_regulator_attributes(rdev);
1879 if (ret < 0)
1880 goto scrub;
1881
1782 /* set supply regulator if it exists */ 1882 /* set supply regulator if it exists */
1783 if (init_data->supply_regulator_dev) { 1883 if (init_data->supply_regulator_dev) {
1784 ret = set_supply(rdev, 1884 ret = set_supply(rdev,