11 #include <linux/kernel.h>
16 #include <linux/slab.h>
23 static int power_state_active_cnt;
32 cnt = power_state_active_cnt;
33 spin_unlock_irqrestore(&power_state_active_lock, flags);
43 power_state_active_cnt++;
44 spin_unlock_irqrestore(&power_state_active_lock, flags);
53 if (power_state_active_cnt <= 0) {
54 pr_err(
"power state: unbalanced enable/disable calls\n");
59 power_state_active_cnt--;
61 spin_unlock_irqrestore(&power_state_active_lock, flags);
65 #ifdef CONFIG_REGULATOR_DEBUG
67 static struct ux500_regulator_debug {
69 struct dentry *status_file;
70 struct dentry *power_state_cnt_file;
73 u8 *state_before_suspend;
74 u8 *state_after_suspend;
77 void ux500_regulator_suspend_debug(
void)
80 for (i = 0; i < rdebug.num_regulators; i++)
81 rdebug.state_before_suspend[i] =
82 rdebug.regulator_array[i].is_enabled;
85 void ux500_regulator_resume_debug(
void)
88 for (i = 0; i < rdebug.num_regulators; i++)
89 rdebug.state_after_suspend[i] =
90 rdebug.regulator_array[i].is_enabled;
93 static int ux500_regulator_power_state_cnt_print(
struct seq_file *
s,
void *
p)
99 err =
seq_printf(s,
"ux500-regulator power state count: %i\n",
102 dev_err(dev,
"seq_printf overflow\n");
107 static int ux500_regulator_power_state_cnt_open(
struct inode *
inode,
110 return single_open(file, ux500_regulator_power_state_cnt_print,
114 static const struct file_operations ux500_regulator_power_state_cnt_fops = {
115 .
open = ux500_regulator_power_state_cnt_open,
122 static int ux500_regulator_status_print(
struct seq_file *s,
void *p)
129 err =
seq_printf(s,
"ux500-regulator status:\n");
131 dev_err(dev,
"seq_printf overflow\n");
133 err =
seq_printf(s,
"%31s : %8s : %8s\n",
"current",
136 dev_err(dev,
"seq_printf overflow\n");
138 for (i = 0; i < rdebug.num_regulators; i++) {
141 info = &rdebug.regulator_array[
i];
146 rdebug.state_before_suspend[i] ?
"enabled" :
"disabled",
147 rdebug.state_after_suspend[i] ?
"enabled" :
"disabled");
149 dev_err(dev,
"seq_printf overflow\n");
157 return single_open(file, ux500_regulator_status_print,
162 .
open = ux500_regulator_status_open,
184 goto exit_no_debugfs;
189 &ux500_regulator_status_fops);
190 if (!rdebug.status_file)
191 goto exit_destroy_dir;
196 &ux500_regulator_power_state_cnt_fops);
197 if (!rdebug.power_state_cnt_file)
198 goto exit_destroy_status;
200 rdebug.regulator_array = regulator_info;
201 rdebug.num_regulators = num_regulators;
203 rdebug.state_before_suspend = kzalloc(num_regulators,
GFP_KERNEL);
204 if (!rdebug.state_before_suspend) {
206 "could not allocate memory for saving state\n");
207 goto exit_destroy_power_state;
210 rdebug.state_after_suspend = kzalloc(num_regulators,
GFP_KERNEL);
211 if (!rdebug.state_after_suspend) {
213 "could not allocate memory for saving state\n");
217 dbx500_regulator_testcase(regulator_info, num_regulators);
221 kfree(rdebug.state_before_suspend);
222 exit_destroy_power_state:
229 dev_err(&pdev->
dev,
"failed to create debugfs entries.\n");
233 int __devexit ux500_regulator_debug_exit(
void)
236 kfree(rdebug.state_after_suspend);
237 kfree(rdebug.state_before_suspend);