aboutsummaryrefslogtreecommitdiff
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMartin Persson <martin.persson@stericsson.com>2010-10-11 13:50:50 +0200
committerSundar Iyer <sundar.iyer@stericsson.com>2010-11-10 14:22:45 +0530
commitf306b23f63ee1c640d4a4b709c7ad2e50cd76815 (patch)
tree9ffb5e1fb13aa2299c55d3fc4dd2d32c25cfee24 /drivers/regulator
parentd919567df51a005710b5cd251ce42c7fb80f2f21 (diff)
Regulators: show consumers that holds a regulator
To locate the consumer(s) that currently holds (ie have enabled) a regulator, a new sysfs entry is created. The consumer(s) are published in /sys/class/regulator/regulator.<#>/use Signed-off-by: Martin Persson <martin.persson@stericsson.com> Change-Id: Ief78276c9685d0bf5688294b9aed9e0698c3475f Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/6549 Reviewed-by: Bengt JONSSON <bengt.g.jonsson@stericsson.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/core.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 2248087b9be..c545cb41a74 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -60,6 +60,7 @@ struct regulator {
char *supply_name;
struct device_attribute dev_attr;
struct regulator_dev *rdev;
+ int use;
};
static int _regulator_is_enabled(struct regulator_dev *rdev);
@@ -517,6 +518,32 @@ static ssize_t regulator_suspend_standby_state_show(struct device *dev,
static DEVICE_ATTR(suspend_standby_state, 0444,
regulator_suspend_standby_state_show, NULL);
+static ssize_t regulator_use_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct regulator_dev *rdev = dev_get_drvdata(dev);
+ struct regulator *reg;
+ size_t size = 0;
+
+ if (rdev->use_count == 0)
+ return sprintf(buf, "no users\n");
+
+ list_for_each_entry(reg, &rdev->consumer_list, list) {
+ if (!reg->use)
+ continue;
+
+ if (reg->dev != NULL)
+ size += sprintf((buf + size), "%s (%d) ",
+ dev_name(reg->dev), reg->use);
+ else
+ size += sprintf((buf + size), "unknown (%d) ",
+ reg->use);
+ }
+ size += sprintf((buf + size), "\n");
+
+ return size;
+}
+static DEVICE_ATTR(use, 0444, regulator_use_show, NULL);
/*
* These are the only attributes are present for all regulators.
@@ -1344,6 +1371,9 @@ int regulator_enable(struct regulator *regulator)
mutex_lock(&rdev->mutex);
ret = _regulator_enable(rdev);
mutex_unlock(&rdev->mutex);
+ if (ret == 0)
+ regulator->use++;
+
return ret;
}
EXPORT_SYMBOL_GPL(regulator_enable);
@@ -1413,6 +1443,9 @@ int regulator_disable(struct regulator *regulator)
mutex_lock(&rdev->mutex);
ret = _regulator_disable(rdev);
mutex_unlock(&rdev->mutex);
+ if (ret == 0)
+ regulator->use--;
+
return ret;
}
EXPORT_SYMBOL_GPL(regulator_disable);
@@ -2137,6 +2170,10 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
struct regulator_ops *ops = rdev->desc->ops;
int status = 0;
+ status = device_create_file(dev, &dev_attr_use);
+ if (status < 0)
+ dev_warn(dev, "Create sysfs file \"use\" failed");
+
/* some attributes need specific methods to be displayed */
if (ops->get_voltage) {
status = device_create_file(dev, &dev_attr_microvolts);