linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] regulator: core: Improve regulator_summary
@ 2018-08-16 20:28 Douglas Anderson
  2018-08-16 20:28 ` [PATCH v2 1/3] regulator: core: Add the opmode to regulator_summary Douglas Anderson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Douglas Anderson @ 2018-08-16 20:28 UTC (permalink / raw)
  To: broonie
  Cc: linux-arm-msm, bjorn.andersson, collinsd, swboyd,
	Douglas Anderson, Liam Girdwood, linux-kernel

The first two patches in this series are useful for those who want to
see the load requested by regulator consumers and also what opmode
they're running in (these two concepts are sometimes linked).

The third patch adds some missing locking for regulator_summary.

All three patches could be applied separately but some rebasing would
be required since the patches touch much of the same code.

Changes in v2:
- No longer consider consumers that don't call regulator_set_load().

Douglas Anderson (3):
  regulator: core: Add the opmode to regulator_summary
  regulator: core: Add consumer-requested load in regulator_summary
  regulator: core: Add locking to debugfs regulator_summary

 drivers/regulator/core.c | 78 ++++++++++++++++++++++++----------------
 1 file changed, 48 insertions(+), 30 deletions(-)

-- 
2.18.0.865.gffc8e1a3cd6-goog


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

* [PATCH v2 1/3] regulator: core: Add the opmode to regulator_summary
  2018-08-16 20:28 [PATCH v2 0/3] regulator: core: Improve regulator_summary Douglas Anderson
@ 2018-08-16 20:28 ` Douglas Anderson
  2018-08-16 20:28 ` [PATCH v2 2/3] regulator: core: Add consumer-requested load in regulator_summary Douglas Anderson
  2018-08-16 20:28 ` [PATCH v2 3/3] regulator: core: Add locking to debugfs regulator_summary Douglas Anderson
  2 siblings, 0 replies; 4+ messages in thread
From: Douglas Anderson @ 2018-08-16 20:28 UTC (permalink / raw)
  To: broonie
  Cc: linux-arm-msm, bjorn.andersson, collinsd, swboyd,
	Douglas Anderson, Liam Girdwood, linux-kernel

It's handy to know what opmode a regulator has been configured to in
the summary.  Add it.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

Changes in v2: None

 drivers/regulator/core.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 6ed568b96c0e..00e931da887a 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -426,19 +426,24 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(name);
 
-static ssize_t regulator_print_opmode(char *buf, int mode)
+static const char *regulator_opmode_to_str(int mode)
 {
 	switch (mode) {
 	case REGULATOR_MODE_FAST:
-		return sprintf(buf, "fast\n");
+		return "fast";
 	case REGULATOR_MODE_NORMAL:
-		return sprintf(buf, "normal\n");
+		return "normal";
 	case REGULATOR_MODE_IDLE:
-		return sprintf(buf, "idle\n");
+		return "idle";
 	case REGULATOR_MODE_STANDBY:
-		return sprintf(buf, "standby\n");
+		return "standby";
 	}
-	return sprintf(buf, "unknown\n");
+	return "unknown";
+}
+
+static ssize_t regulator_print_opmode(char *buf, int mode)
+{
+	return sprintf(buf, "%s\n", regulator_opmode_to_str(mode));
 }
 
 static ssize_t regulator_opmode_show(struct device *dev,
@@ -4660,10 +4665,11 @@ static void regulator_summary_show_subtree(struct seq_file *s,
 	if (!rdev)
 		return;
 
-	seq_printf(s, "%*s%-*s %3d %4d %6d ",
+	seq_printf(s, "%*s%-*s %3d %4d %6d %7s ",
 		   level * 3 + 1, "",
 		   30 - level * 3, rdev_get_name(rdev),
-		   rdev->use_count, rdev->open_count, rdev->bypass_count);
+		   rdev->use_count, rdev->open_count, rdev->bypass_count,
+		   regulator_opmode_to_str(_regulator_get_mode(rdev)));
 
 	seq_printf(s, "%5dmV ", _regulator_get_voltage(rdev) / 1000);
 	seq_printf(s, "%5dmA ", _regulator_get_current_limit(rdev) / 1000);
@@ -4695,7 +4701,7 @@ static void regulator_summary_show_subtree(struct seq_file *s,
 
 		switch (rdev->desc->type) {
 		case REGULATOR_VOLTAGE:
-			seq_printf(s, "%37dmV %5dmV",
+			seq_printf(s, "%45dmV %5dmV",
 				   consumer->voltage[PM_SUSPEND_ON].min_uV / 1000,
 				   consumer->voltage[PM_SUSPEND_ON].max_uV / 1000);
 			break;
@@ -4727,8 +4733,8 @@ static int regulator_summary_show_roots(struct device *dev, void *data)
 
 static int regulator_summary_show(struct seq_file *s, void *data)
 {
-	seq_puts(s, " regulator                      use open bypass voltage current     min     max\n");
-	seq_puts(s, "-------------------------------------------------------------------------------\n");
+	seq_puts(s, " regulator                      use open bypass  opmode voltage current     min     max\n");
+	seq_puts(s, "---------------------------------------------------------------------------------------\n");
 
 	class_for_each_device(&regulator_class, NULL, s,
 			      regulator_summary_show_roots);
-- 
2.18.0.865.gffc8e1a3cd6-goog


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

* [PATCH v2 2/3] regulator: core: Add consumer-requested load in regulator_summary
  2018-08-16 20:28 [PATCH v2 0/3] regulator: core: Improve regulator_summary Douglas Anderson
  2018-08-16 20:28 ` [PATCH v2 1/3] regulator: core: Add the opmode to regulator_summary Douglas Anderson
@ 2018-08-16 20:28 ` Douglas Anderson
  2018-08-16 20:28 ` [PATCH v2 3/3] regulator: core: Add locking to debugfs regulator_summary Douglas Anderson
  2 siblings, 0 replies; 4+ messages in thread
From: Douglas Anderson @ 2018-08-16 20:28 UTC (permalink / raw)
  To: broonie
  Cc: linux-arm-msm, bjorn.andersson, collinsd, swboyd,
	Douglas Anderson, Liam Girdwood, linux-kernel

It's handy to see the load requested by a regulator consumer in the
regulator_summary.  Add it.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

Changes in v2:
- No longer consider consumers that don't call regulator_set_load().

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

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 00e931da887a..1e2dc8d09075 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -4701,7 +4701,8 @@ static void regulator_summary_show_subtree(struct seq_file *s,
 
 		switch (rdev->desc->type) {
 		case REGULATOR_VOLTAGE:
-			seq_printf(s, "%45dmV %5dmV",
+			seq_printf(s, "%37dmA %5dmV %5dmV",
+				   consumer->uA_load / 1000,
 				   consumer->voltage[PM_SUSPEND_ON].min_uV / 1000,
 				   consumer->voltage[PM_SUSPEND_ON].max_uV / 1000);
 			break;
-- 
2.18.0.865.gffc8e1a3cd6-goog


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

* [PATCH v2 3/3] regulator: core: Add locking to debugfs regulator_summary
  2018-08-16 20:28 [PATCH v2 0/3] regulator: core: Improve regulator_summary Douglas Anderson
  2018-08-16 20:28 ` [PATCH v2 1/3] regulator: core: Add the opmode to regulator_summary Douglas Anderson
  2018-08-16 20:28 ` [PATCH v2 2/3] regulator: core: Add consumer-requested load in regulator_summary Douglas Anderson
@ 2018-08-16 20:28 ` Douglas Anderson
  2 siblings, 0 replies; 4+ messages in thread
From: Douglas Anderson @ 2018-08-16 20:28 UTC (permalink / raw)
  To: broonie
  Cc: linux-arm-msm, bjorn.andersson, collinsd, swboyd,
	Douglas Anderson, Liam Girdwood, linux-kernel

Most functions that access the rdev lock the rdev mutex before looking
at data.  ...but not the code that implements the debugfs
regulator_summary.  It probably should though, so let's do it.

Note: this fixes no known issues.  The problem was found only by code
inspection.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

Changes in v2: None

 drivers/regulator/core.c | 51 ++++++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 1e2dc8d09075..d350bcabdf20 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3461,21 +3461,23 @@ int regulator_set_current_limit(struct regulator *regulator,
 }
 EXPORT_SYMBOL_GPL(regulator_set_current_limit);
 
+static int _regulator_get_current_limit_unlocked(struct regulator_dev *rdev)
+{
+	/* sanity check */
+	if (!rdev->desc->ops->get_current_limit)
+		return -EINVAL;
+
+	return rdev->desc->ops->get_current_limit(rdev);
+}
+
 static int _regulator_get_current_limit(struct regulator_dev *rdev)
 {
 	int ret;
 
 	regulator_lock(rdev);
-
-	/* sanity check */
-	if (!rdev->desc->ops->get_current_limit) {
-		ret = -EINVAL;
-		goto out;
-	}
-
-	ret = rdev->desc->ops->get_current_limit(rdev);
-out:
+	ret = _regulator_get_current_limit_unlocked(rdev);
 	regulator_unlock(rdev);
+
 	return ret;
 }
 
@@ -3540,21 +3542,23 @@ int regulator_set_mode(struct regulator *regulator, unsigned int mode)
 }
 EXPORT_SYMBOL_GPL(regulator_set_mode);
 
+static unsigned int _regulator_get_mode_unlocked(struct regulator_dev *rdev)
+{
+	/* sanity check */
+	if (!rdev->desc->ops->get_mode)
+		return -EINVAL;
+
+	return rdev->desc->ops->get_mode(rdev);
+}
+
 static unsigned int _regulator_get_mode(struct regulator_dev *rdev)
 {
 	int ret;
 
 	regulator_lock(rdev);
-
-	/* sanity check */
-	if (!rdev->desc->ops->get_mode) {
-		ret = -EINVAL;
-		goto out;
-	}
-
-	ret = rdev->desc->ops->get_mode(rdev);
-out:
+	ret = _regulator_get_mode_unlocked(rdev);
 	regulator_unlock(rdev);
+
 	return ret;
 }
 
@@ -4661,18 +4665,23 @@ static void regulator_summary_show_subtree(struct seq_file *s,
 	struct regulation_constraints *c;
 	struct regulator *consumer;
 	struct summary_data summary_data;
+	unsigned int opmode;
 
 	if (!rdev)
 		return;
 
+	regulator_lock_nested(rdev, level);
+
+	opmode = _regulator_get_mode_unlocked(rdev);
 	seq_printf(s, "%*s%-*s %3d %4d %6d %7s ",
 		   level * 3 + 1, "",
 		   30 - level * 3, rdev_get_name(rdev),
 		   rdev->use_count, rdev->open_count, rdev->bypass_count,
-		   regulator_opmode_to_str(_regulator_get_mode(rdev)));
+		   regulator_opmode_to_str(opmode));
 
 	seq_printf(s, "%5dmV ", _regulator_get_voltage(rdev) / 1000);
-	seq_printf(s, "%5dmA ", _regulator_get_current_limit(rdev) / 1000);
+	seq_printf(s, "%5dmA ",
+		   _regulator_get_current_limit_unlocked(rdev) / 1000);
 
 	c = rdev->constraints;
 	if (c) {
@@ -4719,6 +4728,8 @@ static void regulator_summary_show_subtree(struct seq_file *s,
 
 	class_for_each_device(&regulator_class, NULL, &summary_data,
 			      regulator_summary_show_children);
+
+	regulator_unlock(rdev);
 }
 
 static int regulator_summary_show_roots(struct device *dev, void *data)
-- 
2.18.0.865.gffc8e1a3cd6-goog


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

end of thread, other threads:[~2018-08-16 20:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-16 20:28 [PATCH v2 0/3] regulator: core: Improve regulator_summary Douglas Anderson
2018-08-16 20:28 ` [PATCH v2 1/3] regulator: core: Add the opmode to regulator_summary Douglas Anderson
2018-08-16 20:28 ` [PATCH v2 2/3] regulator: core: Add consumer-requested load in regulator_summary Douglas Anderson
2018-08-16 20:28 ` [PATCH v2 3/3] regulator: core: Add locking to debugfs regulator_summary Douglas Anderson

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).