]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
pwm: Add debugfs interface
authorThierry Reding <thierry.reding@avionic-design.de>
Mon, 26 Mar 2012 07:31:48 +0000 (09:31 +0200)
committerThierry Reding <thierry.reding@avionic-design.de>
Fri, 15 Jun 2012 10:56:53 +0000 (12:56 +0200)
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.

Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Reviewed-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
drivers/pwm/core.c
include/linux/pwm.h

index a447be1283280d4b092efa8598873ef8c9c59ed9..aadc1d79744962442d8a6b632aa96691bd421320 100644 (file)
@@ -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
 
@@ -338,3 +340,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 */
index 57103911f4c759a907ff827f7f028bfad9f4ce66..047cd5351a3bfe2c92b5e2cca10ff47a2f8e6ac4 100644 (file)
@@ -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;
 };