linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] regulator: Display in use regulators in sysfs
@ 2013-01-22  9:46 Lee Jones
  2013-01-23  2:51 ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Lee Jones @ 2013-01-22  9:46 UTC (permalink / raw)
  To: broonie; +Cc: linux-kernel

Please excuse any poor formatting that may occur, as this is
copy-paste into my mailer, but what do you think of this idea?

To locate a consumer that currently holds a regulattor, a new sysfs
entry is created. The consumer are published in
/sys/class/regulator/regulator.<#>/use.

---
 drivers/regulator/core.c |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 046fb1b..40fd150 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -81,6 +81,7 @@ struct regulator {
   struct device_attribute dev_attr;
   struct regulator_dev *rdev;
   struct dentry *debugfs;
+  int use;
 };
 
 static int _regulator_is_enabled(struct regulator_dev *rdev);
@@ -602,6 +603,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.
@@ -1540,6 +1567,8 @@ int regulator_enable(struct regulator
*regulator)
 
	if (ret != 0 && rdev->supply)
 	        regulator_disable(rdev->supply);
+	else
+		regulator->use++;
 
	return ret;
 }
@@ -1613,6 +1642,9 @@ int regulator_disable(struct regulator
*regulator)
	if (ret == 0 && rdev->supply)
 	   regulator_disable(rdev->supply);
 
+	if (ret == 0)
+	        regulator->use--;
+
	return ret;
 }
 EXPORT_SYMBOL_GPL(regulator_disable);
@@ -2699,6 +2731,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 && ops->get_voltage(rdev) >= 0) ||
 	    (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0))
	        {

-- 
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC] regulator: Display in use regulators in sysfs
  2013-01-22  9:46 [RFC] regulator: Display in use regulators in sysfs Lee Jones
@ 2013-01-23  2:51 ` Mark Brown
  2013-01-23  8:19   ` Lee Jones
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2013-01-23  2:51 UTC (permalink / raw)
  To: Lee Jones; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 390 bytes --]

On Tue, Jan 22, 2013 at 09:46:24AM +0000, Lee Jones wrote:

> To locate a consumer that currently holds a regulattor, a new sysfs
> entry is created. The consumer are published in
> /sys/class/regulator/regulator.<#>/use.

We call our reference counts use count but this was in fact the original
design, the local reference counts got dropped due to David Brownell's
forceful insistance :/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] regulator: Display in use regulators in sysfs
  2013-01-23  2:51 ` Mark Brown
@ 2013-01-23  8:19   ` Lee Jones
  2013-01-23 15:53     ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Lee Jones @ 2013-01-23  8:19 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel

On Wed, 23 Jan 2013, Mark Brown wrote:

> On Tue, Jan 22, 2013 at 09:46:24AM +0000, Lee Jones wrote:
> 
> > To locate a consumer that currently holds a regulattor, a new sysfs
> > entry is created. The consumer are published in
> > /sys/class/regulator/regulator.<#>/use.
> 
> We call our reference counts use count but this was in fact the original
> design, the local reference counts got dropped due to David Brownell's
> forceful insistance :/

So I should pull the patch?

How do you feel about being able to access it via sysfs? Good or bad
idea? If it's a good idea, I can always change the name of the
variable?

-- 
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] regulator: Display in use regulators in sysfs
  2013-01-23  8:19   ` Lee Jones
@ 2013-01-23 15:53     ` Mark Brown
  2013-01-24  9:11       ` Lee Jones
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2013-01-23 15:53 UTC (permalink / raw)
  To: Lee Jones; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

On Wed, Jan 23, 2013 at 08:19:27AM +0000, Lee Jones wrote:
> On Wed, 23 Jan 2013, Mark Brown wrote:

> > We call our reference counts use count but this was in fact the original
> > design, the local reference counts got dropped due to David Brownell's
> > forceful insistance :/

> So I should pull the patch?

Not sure what you mean by pull; a stright revert won't work.

> How do you feel about being able to access it via sysfs? Good or bad
> idea? If it's a good idea, I can always change the name of the
> variable?

That or debugfs.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] regulator: Display in use regulators in sysfs
  2013-01-23 15:53     ` Mark Brown
@ 2013-01-24  9:11       ` Lee Jones
  2013-01-24 10:06         ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Lee Jones @ 2013-01-24  9:11 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel

On Wed, 23 Jan 2013, Mark Brown wrote:

> On Wed, Jan 23, 2013 at 08:19:27AM +0000, Lee Jones wrote:
> > On Wed, 23 Jan 2013, Mark Brown wrote:
> 
> > > We call our reference counts use count but this was in fact the original
> > > design, the local reference counts got dropped due to David Brownell's
> > > forceful insistance :/
> 
> > So I should pull the patch?
> 
> Not sure what you mean by pull; a stright revert won't work.

Sorry, perhaps I should have been clearer. 

Is the patch any good, or should I throw it in the bin (pull it)?

> > How do you feel about being able to access it via sysfs? Good or bad
> > idea? If it's a good idea, I can always change the name of the
> > variable?
> 
> That or debugfs.

So the premise of the patch is good and is worth updating and upstreaming?

-- 
Lee Jones
Linaro ST-Ericsson Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC] regulator: Display in use regulators in sysfs
  2013-01-24  9:11       ` Lee Jones
@ 2013-01-24 10:06         ` Mark Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2013-01-24 10:06 UTC (permalink / raw)
  To: Lee Jones; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 143 bytes --]

On Thu, Jan 24, 2013 at 09:11:34AM +0000, Lee Jones wrote:

> So the premise of the patch is good and is worth updating and upstreaming?

Yes.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-01-24 10:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-22  9:46 [RFC] regulator: Display in use regulators in sysfs Lee Jones
2013-01-23  2:51 ` Mark Brown
2013-01-23  8:19   ` Lee Jones
2013-01-23 15:53     ` Mark Brown
2013-01-24  9:11       ` Lee Jones
2013-01-24 10:06         ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).