Commit bc558a60b58f638ee0188affb627d4894a97b1c7

Authored by Mark Brown
Committed by Liam Girdwood
1 parent 42fad570b6

regulator: Export regulator name via sysfs

Provide a new file 'name' in the regulator sysfs class with a human
readable name for the regulator for use in applications.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>

Showing 2 changed files with 31 additions and 0 deletions Side-by-side Diff

Documentation/ABI/testing/sysfs-class-regulator
... ... @@ -157,6 +157,19 @@
157 157 platform code.
158 158  
159 159  
  160 +What: /sys/class/regulator/.../name
  161 +Date: October 2008
  162 +KernelVersion: 2.6.28
  163 +Contact: Liam Girdwood <lrg@slimlogic.co.uk>
  164 +Description:
  165 + Each regulator directory will contain a field called
  166 + name. This holds a string identifying the regulator for
  167 + display purposes.
  168 +
  169 + NOTE: this will be empty if no suitable name is provided
  170 + by platform or regulator drivers.
  171 +
  172 +
160 173 What: /sys/class/regulator/.../num_users
161 174 Date: April 2008
162 175 KernelVersion: 2.6.26
drivers/regulator/core.c
... ... @@ -241,6 +241,22 @@
241 241 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
242 242 }
243 243  
  244 +static ssize_t regulator_name_show(struct device *dev,
  245 + struct device_attribute *attr, char *buf)
  246 +{
  247 + struct regulator_dev *rdev = dev_get_drvdata(dev);
  248 + const char *name;
  249 +
  250 + if (rdev->constraints->name)
  251 + name = rdev->constraints->name;
  252 + else if (rdev->desc->name)
  253 + name = rdev->desc->name;
  254 + else
  255 + name = "";
  256 +
  257 + return sprintf(buf, "%s\n", name);
  258 +}
  259 +
244 260 static ssize_t regulator_opmode_show(struct device *dev,
245 261 struct device_attribute *attr, char *buf)
246 262 {
247 263  
... ... @@ -473,7 +489,9 @@
473 489 else
474 490 return sprintf(buf, "disabled\n");
475 491 }
  492 +
476 493 static struct device_attribute regulator_dev_attrs[] = {
  494 + __ATTR(name, 0444, regulator_name_show, NULL),
477 495 __ATTR(microvolts, 0444, regulator_uV_show, NULL),
478 496 __ATTR(microamps, 0444, regulator_uA_show, NULL),
479 497 __ATTR(opmode, 0444, regulator_opmode_show, NULL),