diff mbox

[v6,03/17] pwm: Add debugfs interface

Message ID 1334070400-25013-4-git-send-email-thierry.reding@avionic-design.de
State Not Applicable, archived
Headers show

Commit Message

Thierry Reding April 10, 2012, 3:06 p.m. UTC
This commit adds a debugfs interface that can be used to list the
current internal state of the PWM devices registered with the PWM
framework.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Reviewed-by: Reviewed-by: Shawn Guo <shawn.guo@linaro.org>
---
Changes in v5:
- new patch splitting off debugfs interface implementation
- use seq_file's iterator interface for debugfs support
- add missing forward declaration of struct seq_file

 drivers/pwm/core.c  |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pwm.h |    6 ++++
 2 files changed, 96 insertions(+)

Comments

Shawn Guo April 11, 2012, 12:33 p.m. UTC | #1
On Tue, Apr 10, 2012 at 05:06:26PM +0200, Thierry Reding wrote:
> This commit adds a debugfs interface that can be used to list the
> current internal state of the PWM devices registered with the PWM
> framework.
> 
> Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
> Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> Reviewed-by: Reviewed-by: Shawn Guo <shawn.guo@linaro.org>

I have done review only once :)
Thierry Reding April 11, 2012, 12:38 p.m. UTC | #2
* Shawn Guo wrote:
> On Tue, Apr 10, 2012 at 05:06:26PM +0200, Thierry Reding wrote:
> > This commit adds a debugfs interface that can be used to list the
> > current internal state of the PWM devices registered with the PWM
> > framework.
> > 
> > Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
> > Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> > Reviewed-by: Reviewed-by: Shawn Guo <shawn.guo@linaro.org>
> 
> I have done review only once :)

Heh, good catch! =)

Thanks,
Thierry
Mark Brown April 11, 2012, 3:11 p.m. UTC | #3
On Wed, Apr 11, 2012 at 08:33:56PM +0800, Shawn Guo wrote:
> On Tue, Apr 10, 2012 at 05:06:26PM +0200, Thierry Reding wrote:

> > Reviewed-by: Reviewed-by: Shawn Guo <shawn.guo@linaro.org>

> I have done review only once :)

But it was a really thorough and detailed review!
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 8688754..7e13da1 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -27,6 +27,8 @@ 
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/device.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
 
 #define MAX_PWMS 1024
 
@@ -334,3 +336,91 @@  void pwm_disable(struct pwm_device *pwm)
 		pwm->chip->ops->disable(pwm->chip, pwm);
 }
 EXPORT_SYMBOL_GPL(pwm_disable);
+
+#ifdef CONFIG_DEBUG_FS
+static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s)
+{
+	unsigned int i;
+
+	for (i = 0; i < chip->npwm; i++) {
+		struct pwm_device *pwm = &chip->pwms[i];
+
+		seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label);
+
+		if (test_bit(PWMF_REQUESTED, &pwm->flags))
+			seq_printf(s, " requested");
+
+		if (test_bit(PWMF_ENABLED, &pwm->flags))
+			seq_printf(s, " enabled");
+
+		seq_printf(s, "\n");
+	}
+}
+
+static void *pwm_seq_start(struct seq_file *s, loff_t *pos)
+{
+	mutex_lock(&pwm_lock);
+	s->private = "";
+
+	return seq_list_start(&pwm_chips, *pos);
+}
+
+static void *pwm_seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	s->private = "\n";
+
+	return seq_list_next(v, &pwm_chips, pos);
+}
+
+static void pwm_seq_stop(struct seq_file *s, void *v)
+{
+	mutex_unlock(&pwm_lock);
+}
+
+static int pwm_seq_show(struct seq_file *s, void *v)
+{
+	struct pwm_chip *chip = list_entry(v, struct pwm_chip, list);
+
+	seq_printf(s, "%s%s/%s, %d PWM device%s\n", (char *)s->private,
+		   chip->dev->bus ? chip->dev->bus->name : "no-bus",
+		   dev_name(chip->dev), chip->npwm,
+		   (chip->npwm != 1) ? "s" : "");
+
+	if (chip->ops->dbg_show)
+		chip->ops->dbg_show(chip, s);
+	else
+		pwm_dbg_show(chip, s);
+
+	return 0;
+}
+
+static const struct seq_operations pwm_seq_ops = {
+	.start = pwm_seq_start,
+	.next = pwm_seq_next,
+	.stop = pwm_seq_stop,
+	.show = pwm_seq_show,
+};
+
+static int pwm_seq_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &pwm_seq_ops);
+}
+
+static const struct file_operations pwm_debugfs_ops = {
+	.owner = THIS_MODULE,
+	.open = pwm_seq_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = seq_release,
+};
+
+static int __init pwm_debugfs_init(void)
+{
+	debugfs_create_file("pwm", S_IFREG | S_IRUGO, NULL, NULL,
+			    &pwm_debugfs_ops);
+
+	return 0;
+}
+
+subsys_initcall(pwm_debugfs_init);
+#endif /* CONFIG_DEBUG_FS */
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 5710391..047cd53 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -2,6 +2,7 @@ 
 #define __LINUX_PWM_H
 
 struct pwm_device;
+struct seq_file;
 
 /*
  * pwm_request - request a PWM device
@@ -65,6 +66,7 @@  static inline unsigned int pwm_get_period(struct pwm_device *pwm)
  * @config: configure duty cycles and period length for this PWM
  * @enable: enable PWM output toggling
  * @disable: disable PWM output toggling
+ * @dbg_show: optional routine to show contents in debugfs
  * @owner: helps prevent removal of modules exporting active PWMs
  */
 struct pwm_ops {
@@ -79,6 +81,10 @@  struct pwm_ops {
 					  struct pwm_device *pwm);
 	void			(*disable)(struct pwm_chip *chip,
 					   struct pwm_device *pwm);
+#ifdef CONFIG_DEBUG_FS
+	void			(*dbg_show)(struct pwm_chip *chip,
+					    struct seq_file *s);
+#endif
 	struct module		*owner;
 };