diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index ae99fd54e855..6bcf755d0dae 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -54,6 +54,7 @@ static LIST_HEAD(regulator_ena_gpio_list); static LIST_HEAD(regulator_supply_alias_list); static LIST_HEAD(regulator_coupler_list); static bool has_full_constraints; +static bool debug_suspend; static struct dentry *debugfs_root; @@ -6024,6 +6025,74 @@ static int regulator_summary_show(struct seq_file *s, void *data) DEFINE_SHOW_ATTRIBUTE(regulator_summary); #endif /* CONFIG_DEBUG_FS */ +#ifdef CONFIG_REGULATOR_QTI_DEBUG +static int _regulator_debug_print_enabled(struct device *dev, void *data) +{ + struct regulator_dev *rdev = dev_to_rdev(dev); + struct regulator *reg; + const char *supply_name; + int mode = -EPERM; + int uV = -EPERM; + + if (_regulator_is_enabled(rdev) <= 0) + return 0; + + uV = regulator_get_voltage_rdev(rdev); + + if (rdev->desc->ops->get_mode) + mode = rdev->desc->ops->get_mode(rdev); + + if (uV != -EPERM && mode != -EPERM) + pr_info("%s[%u] %d uV, mode=%d\n", + rdev_get_name(rdev), rdev->use_count, uV, mode); + else if (uV != -EPERM) + pr_info("%s[%u] %d uV\n", + rdev_get_name(rdev), rdev->use_count, uV); + else if (mode != -EPERM) + pr_info("%s[%u], mode=%d\n", + rdev_get_name(rdev), rdev->use_count, mode); + else + pr_info("%s[%u]\n", rdev_get_name(rdev), rdev->use_count); + + /* Print a header if there are consumers. */ + if (rdev->open_count) + pr_info(" %-32s EN Min_uV Max_uV load_uA\n", + "Device-Supply"); + + list_for_each_entry(reg, &rdev->consumer_list, list) { + if (reg->supply_name) + supply_name = reg->supply_name; + else + supply_name = "(null)-(null)"; + + pr_info(" %-32s %d %8d %8d %8d\n", supply_name, + reg->enable_count, + reg->voltage[PM_SUSPEND_ON].min_uV, + reg->voltage[PM_SUSPEND_ON].max_uV, + reg->uA_load); + } + + return 0; +} + +/** + * regulator_debug_print_enabled - log enabled regulators + * + * Print the names of all enabled regulators and their consumers to the kernel + * log if debug_suspend is set from debugfs. + */ +void regulator_debug_print_enabled(void) +{ + if (likely(!debug_suspend)) + return; + + pr_info("Enabled regulators:\n"); + class_for_each_device(®ulator_class, NULL, NULL, + _regulator_debug_print_enabled); +} +EXPORT_SYMBOL(regulator_debug_print_enabled); +#endif /* CONFIG_REGULATOR_QTI_DEBUG */ + static int __init regulator_init(void) { int ret; @@ -6040,6 +6109,9 @@ static int __init regulator_init(void) debugfs_create_file("regulator_summary", 0444, debugfs_root, NULL, ®ulator_summary_fops); + + debugfs_create_bool("debug_suspend", 0644, debugfs_root, + &debug_suspend); #endif regulator_dummy_init(); diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h index a84cc8879c3e..d9e56e6d8071 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -253,6 +253,14 @@ static inline void regulator_has_full_constraints(void) } #endif +#ifdef CONFIG_REGULATOR_QTI_DEBUG +void regulator_debug_print_enabled(void); +#else +static inline void regulator_debug_print_enabled(void) +{ +} +#endif + static inline int regulator_suspend_prepare(suspend_state_t state) { return 0;