public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] regulator: core: Add debugfs to show constraint flags
@ 2016-04-21 12:36 Richard Fitzgerald
  2016-04-21 15:06 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Fitzgerald @ 2016-04-21 12:36 UTC (permalink / raw)
  To: broonie; +Cc: lgirdwood, linux-kernel, patches

There are debugfs entries for voltage and current, but not for
the constraint flags. It's useful for debugging to be able to
see what these flags are so this patch adds a new debugfs file.
We can't use debugfs_create_bool for this because the flags are
bitfields, so as this needs a special read callback they have been
collected into a single file that lists all the flags.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
---
 drivers/regulator/core.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index e0b7642..b48a2ec 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1272,6 +1272,50 @@ static void unset_regulator_supplies(struct regulator_dev *rdev)
 	}
 }
 
+#ifdef CONFIG_DEBUG_FS
+static ssize_t constraint_flags_read_file(struct file *file,
+					  char __user *user_buf,
+					  size_t count, loff_t *ppos)
+{
+	const struct regulator *regulator = file->private_data;
+	const struct regulation_constraints *c = regulator->rdev->constraints;
+	char *buf;
+	ssize_t ret;
+
+	if (!c)
+		return 0;
+
+	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = snprintf(buf, PAGE_SIZE,
+		"always_on: %u\nboot_on: %u\napply_uV: %u\nramp_disable: %u\n"
+		"soft_start: %u\npull_down: %u\nover_current_protection: %u\n",
+		!!c->always_on,
+		!!c->boot_on,
+		!!c->apply_uV,
+		!!c->ramp_disable,
+		!!c->soft_start,
+		!!c->pull_down,
+		!!c->over_current_protection);
+
+	ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+	kfree(buf);
+
+	return ret;
+}
+
+#endif
+
+static const struct file_operations constraint_flags_fops = {
+#ifdef CONFIG_DEBUG_FS
+	.open = simple_open,
+	.read = constraint_flags_read_file,
+	.llseek = default_llseek,
+#endif
+};
+
 #define REG_STR_SIZE	64
 
 static struct regulator *create_regulator(struct regulator_dev *rdev,
@@ -1327,6 +1371,9 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
 				   &regulator->min_uV);
 		debugfs_create_u32("max_uV", 0444, regulator->debugfs,
 				   &regulator->max_uV);
+		debugfs_create_file("constraint_flags", 0444,
+				    regulator->debugfs, regulator,
+				    &constraint_flags_fops);
 	}
 
 	/*
-- 
1.9.1

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

* Re: [PATCH v2] regulator: core: Add debugfs to show constraint flags
  2016-04-21 12:36 [PATCH v2] regulator: core: Add debugfs to show constraint flags Richard Fitzgerald
@ 2016-04-21 15:06 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2016-04-21 15:06 UTC (permalink / raw)
  To: Richard Fitzgerald; +Cc: lgirdwood, linux-kernel, patches

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

On Thu, Apr 21, 2016 at 01:36:14PM +0100, Richard Fitzgerald wrote:

> +	ret = snprintf(buf, PAGE_SIZE,
> +		"always_on: %u\nboot_on: %u\napply_uV: %u\nramp_disable: %u\n"
> +		"soft_start: %u\npull_down: %u\nover_current_protection: %u\n",
> +		!!c->always_on,
> +		!!c->boot_on,
> +		!!c->apply_uV,
> +		!!c->ramp_disable,
> +		!!c->soft_start,
> +		!!c->pull_down,
> +		!!c->over_current_protection);

Can we try for legibility please?  Trying to cram everything onto the
minimum number of lines really doesn't help and the !!s either do
nothing or will end up obscuring information down the line.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

end of thread, other threads:[~2016-04-21 15:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-21 12:36 [PATCH v2] regulator: core: Add debugfs to show constraint flags Richard Fitzgerald
2016-04-21 15: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