Blame view

drivers/regulator/dbx500-prcmu.c 4.37 KB
0376148f3   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
38e968380   Bengt Jonsson   regulators/db8500...
2
3
4
  /*
   * Copyright (C) ST-Ericsson SA 2010
   *
38e968380   Bengt Jonsson   regulators/db8500...
5
6
7
8
9
10
11
12
13
14
15
16
   * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
   *          Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
   *
   * UX500 common part of Power domain regulators
   */
  
  #include <linux/kernel.h>
  #include <linux/err.h>
  #include <linux/regulator/driver.h>
  #include <linux/debugfs.h>
  #include <linux/seq_file.h>
  #include <linux/slab.h>
7f46d0f81   Steven Rostedt   regulators: db850...
17
  #include <linux/module.h>
38e968380   Bengt Jonsson   regulators/db8500...
18
19
20
21
22
23
24
25
  
  #include "dbx500-prcmu.h"
  
  /*
   * power state reference count
   */
  static int power_state_active_cnt; /* will initialize to zero */
  static DEFINE_SPINLOCK(power_state_active_lock);
38e968380   Bengt Jonsson   regulators/db8500...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  void power_state_active_enable(void)
  {
  	unsigned long flags;
  
  	spin_lock_irqsave(&power_state_active_lock, flags);
  	power_state_active_cnt++;
  	spin_unlock_irqrestore(&power_state_active_lock, flags);
  }
  
  int power_state_active_disable(void)
  {
  	int ret = 0;
  	unsigned long flags;
  
  	spin_lock_irqsave(&power_state_active_lock, flags);
  	if (power_state_active_cnt <= 0) {
  		pr_err("power state: unbalanced enable/disable calls
  ");
  		ret = -EINVAL;
  		goto out;
  	}
  
  	power_state_active_cnt--;
  out:
  	spin_unlock_irqrestore(&power_state_active_lock, flags);
  	return ret;
  }
  
  #ifdef CONFIG_REGULATOR_DEBUG
3d75095a5   Sachin Kamat   regulator: dbx500...
55
56
57
58
59
60
61
62
63
64
65
  static int power_state_active_get(void)
  {
  	unsigned long flags;
  	int cnt;
  
  	spin_lock_irqsave(&power_state_active_lock, flags);
  	cnt = power_state_active_cnt;
  	spin_unlock_irqrestore(&power_state_active_lock, flags);
  
  	return cnt;
  }
38e968380   Bengt Jonsson   regulators/db8500...
66
67
68
69
70
71
72
73
74
  static struct ux500_regulator_debug {
  	struct dentry *dir;
  	struct dentry *status_file;
  	struct dentry *power_state_cnt_file;
  	struct dbx500_regulator_info *regulator_array;
  	int num_regulators;
  	u8 *state_before_suspend;
  	u8 *state_after_suspend;
  } rdebug;
3e60b4fc8   Yangtao Li   regulator: conver...
75
  static int ux500_regulator_power_state_cnt_show(struct seq_file *s, void *p)
38e968380   Bengt Jonsson   regulators/db8500...
76
  {
38e968380   Bengt Jonsson   regulators/db8500...
77
  	/* print power state count */
af78114ec   Joe Perches   regulator: dbx500...
78
79
80
  	seq_printf(s, "ux500-regulator power state count: %i
  ",
  		   power_state_active_get());
38e968380   Bengt Jonsson   regulators/db8500...
81
82
83
  
  	return 0;
  }
3e60b4fc8   Yangtao Li   regulator: conver...
84
  DEFINE_SHOW_ATTRIBUTE(ux500_regulator_power_state_cnt);
38e968380   Bengt Jonsson   regulators/db8500...
85

3e60b4fc8   Yangtao Li   regulator: conver...
86
  static int ux500_regulator_status_show(struct seq_file *s, void *p)
38e968380   Bengt Jonsson   regulators/db8500...
87
  {
38e968380   Bengt Jonsson   regulators/db8500...
88
89
90
  	int i;
  
  	/* print dump header */
af78114ec   Joe Perches   regulator: dbx500...
91
92
93
94
  	seq_puts(s, "ux500-regulator status:
  ");
  	seq_printf(s, "%31s : %8s : %8s
  ", "current", "before", "after");
38e968380   Bengt Jonsson   regulators/db8500...
95
96
97
98
99
100
101
  
  	for (i = 0; i < rdebug.num_regulators; i++) {
  		struct dbx500_regulator_info *info;
  		/* Access per-regulator data */
  		info = &rdebug.regulator_array[i];
  
  		/* print status */
af78114ec   Joe Perches   regulator: dbx500...
102
103
104
105
106
107
  		seq_printf(s, "%20s : %8s : %8s : %8s
  ",
  			   info->desc.name,
  			   info->is_enabled ? "enabled" : "disabled",
  			   rdebug.state_before_suspend[i] ? "enabled" : "disabled",
  			   rdebug.state_after_suspend[i] ? "enabled" : "disabled");
38e968380   Bengt Jonsson   regulators/db8500...
108
109
110
111
  	}
  
  	return 0;
  }
3e60b4fc8   Yangtao Li   regulator: conver...
112
  DEFINE_SHOW_ATTRIBUTE(ux500_regulator_status);
38e968380   Bengt Jonsson   regulators/db8500...
113
114
115
116
117
118
119
  
  int __attribute__((weak)) dbx500_regulator_testcase(
  	struct dbx500_regulator_info *regulator_info,
  	int num_regulators)
  {
  	return 0;
  }
a5023574d   Bill Pemberton   regulator: remove...
120
  int
38e968380   Bengt Jonsson   regulators/db8500...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  ux500_regulator_debug_init(struct platform_device *pdev,
  	struct dbx500_regulator_info *regulator_info,
  	int num_regulators)
  {
  	/* create directory */
  	rdebug.dir = debugfs_create_dir("ux500-regulator", NULL);
  	if (!rdebug.dir)
  		goto exit_no_debugfs;
  
  	/* create "status" file */
  	rdebug.status_file = debugfs_create_file("status",
  		S_IRUGO, rdebug.dir, &pdev->dev,
  		&ux500_regulator_status_fops);
  	if (!rdebug.status_file)
  		goto exit_destroy_dir;
  
  	/* create "power-state-count" file */
  	rdebug.power_state_cnt_file = debugfs_create_file("power-state-count",
  		S_IRUGO, rdebug.dir, &pdev->dev,
  		&ux500_regulator_power_state_cnt_fops);
  	if (!rdebug.power_state_cnt_file)
  		goto exit_destroy_status;
  
  	rdebug.regulator_array = regulator_info;
  	rdebug.num_regulators = num_regulators;
  
  	rdebug.state_before_suspend = kzalloc(num_regulators, GFP_KERNEL);
cb487c5c0   Sachin Kamat   regulator: dbx500...
148
  	if (!rdebug.state_before_suspend)
38e968380   Bengt Jonsson   regulators/db8500...
149
  		goto exit_destroy_power_state;
38e968380   Bengt Jonsson   regulators/db8500...
150
151
  
  	rdebug.state_after_suspend = kzalloc(num_regulators, GFP_KERNEL);
cb487c5c0   Sachin Kamat   regulator: dbx500...
152
  	if (!rdebug.state_after_suspend)
38e968380   Bengt Jonsson   regulators/db8500...
153
  		goto exit_free;
38e968380   Bengt Jonsson   regulators/db8500...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
  
  	dbx500_regulator_testcase(regulator_info, num_regulators);
  	return 0;
  
  exit_free:
  	kfree(rdebug.state_before_suspend);
  exit_destroy_power_state:
  	debugfs_remove(rdebug.power_state_cnt_file);
  exit_destroy_status:
  	debugfs_remove(rdebug.status_file);
  exit_destroy_dir:
  	debugfs_remove(rdebug.dir);
  exit_no_debugfs:
  	dev_err(&pdev->dev, "failed to create debugfs entries.
  ");
  	return -ENOMEM;
  }
8dc995f56   Bill Pemberton   regulator: remove...
171
  int ux500_regulator_debug_exit(void)
38e968380   Bengt Jonsson   regulators/db8500...
172
173
174
175
176
177
178
179
  {
  	debugfs_remove_recursive(rdebug.dir);
  	kfree(rdebug.state_after_suspend);
  	kfree(rdebug.state_before_suspend);
  
  	return 0;
  }
  #endif