Commit 1130e5b3 authored by Mark Brown's avatar Mark Brown Committed by Liam Girdwood

regulator: Add initial per-regulator debugfs support

We only expose the use and open counts to userspace, providing a tiny
bit of insight into what the API is up to.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
parent 21cf891a
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/debugfs.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -47,6 +48,10 @@ static LIST_HEAD(regulator_map_list); ...@@ -47,6 +48,10 @@ static LIST_HEAD(regulator_map_list);
static bool has_full_constraints; static bool has_full_constraints;
static bool board_wants_dummy_regulator; static bool board_wants_dummy_regulator;
#ifdef CONFIG_DEBUG_FS
static struct dentry *debugfs_root;
#endif
/* /*
* struct regulator_map * struct regulator_map
* *
...@@ -2404,6 +2409,23 @@ static int add_regulator_attributes(struct regulator_dev *rdev) ...@@ -2404,6 +2409,23 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
return status; return status;
} }
static void rdev_init_debugfs(struct regulator_dev *rdev)
{
#ifdef CONFIG_DEBUG_FS
rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root);
if (IS_ERR(rdev->debugfs) || !rdev->debugfs) {
rdev_warn(rdev, "Failed to create debugfs directory\n");
rdev->debugfs = NULL;
return;
}
debugfs_create_u32("use_count", 0444, rdev->debugfs,
&rdev->use_count);
debugfs_create_u32("open_count", 0444, rdev->debugfs,
&rdev->open_count);
#endif
}
/** /**
* regulator_register - register regulator * regulator_register - register regulator
* @regulator_desc: regulator to register * @regulator_desc: regulator to register
...@@ -2548,6 +2570,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, ...@@ -2548,6 +2570,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
} }
list_add(&rdev->list, &regulator_list); list_add(&rdev->list, &regulator_list);
rdev_init_debugfs(rdev);
out: out:
mutex_unlock(&regulator_list_mutex); mutex_unlock(&regulator_list_mutex);
return rdev; return rdev;
...@@ -2580,6 +2604,9 @@ void regulator_unregister(struct regulator_dev *rdev) ...@@ -2580,6 +2604,9 @@ void regulator_unregister(struct regulator_dev *rdev)
return; return;
mutex_lock(&regulator_list_mutex); mutex_lock(&regulator_list_mutex);
#ifdef CONFIG_DEBUG_FS
debugfs_remove_recursive(rdev->debugfs);
#endif
WARN_ON(rdev->open_count); WARN_ON(rdev->open_count);
unset_regulator_supplies(rdev); unset_regulator_supplies(rdev);
list_del(&rdev->list); list_del(&rdev->list);
...@@ -2723,6 +2750,14 @@ static int __init regulator_init(void) ...@@ -2723,6 +2750,14 @@ static int __init regulator_init(void)
ret = class_register(&regulator_class); ret = class_register(&regulator_class);
#ifdef CONFIG_DEBUG_FS
debugfs_root = debugfs_create_dir("regulator", NULL);
if (IS_ERR(debugfs_root) || !debugfs_root) {
pr_warn("regulator: Failed to create debugfs directory\n");
debugfs_root = NULL;
}
#endif
regulator_dummy_init(); regulator_dummy_init();
return ret; return ret;
......
...@@ -175,9 +175,9 @@ struct regulator_desc { ...@@ -175,9 +175,9 @@ struct regulator_desc {
*/ */
struct regulator_dev { struct regulator_dev {
struct regulator_desc *desc; struct regulator_desc *desc;
int use_count;
int open_count;
int exclusive; int exclusive;
u32 use_count;
u32 open_count;
/* lists we belong to */ /* lists we belong to */
struct list_head list; /* list of all regulators */ struct list_head list; /* list of all regulators */
...@@ -195,6 +195,10 @@ struct regulator_dev { ...@@ -195,6 +195,10 @@ struct regulator_dev {
struct regulator_dev *supply; /* for tree */ struct regulator_dev *supply; /* for tree */
void *reg_data; /* regulator_dev data */ void *reg_data; /* regulator_dev data */
#ifdef CONFIG_DEBUG_FS
struct dentry *debugfs;
#endif
}; };
struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment