diff options
-rw-r--r-- | Documentation/ABI/testing/sysfs-class-regulator | 315 | ||||
-rw-r--r-- | Documentation/power/regulator/consumer.txt | 182 | ||||
-rw-r--r-- | Documentation/power/regulator/machine.txt | 101 | ||||
-rw-r--r-- | Documentation/power/regulator/overview.txt | 171 | ||||
-rw-r--r-- | Documentation/power/regulator/regulator.txt | 30 | ||||
-rw-r--r-- | MAINTAINERS | 9 | ||||
-rw-r--r-- | arch/arm/Kconfig | 2 | ||||
-rw-r--r-- | drivers/Makefile | 1 | ||||
-rw-r--r-- | drivers/regulator/Kconfig | 59 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 12 | ||||
-rw-r--r-- | drivers/regulator/bq24022.c | 167 | ||||
-rw-r--r-- | drivers/regulator/core.c | 1903 | ||||
-rw-r--r-- | drivers/regulator/fixed.c | 129 | ||||
-rw-r--r-- | drivers/regulator/virtual.c | 345 | ||||
-rw-r--r-- | include/linux/regulator/bq24022.h | 21 | ||||
-rw-r--r-- | include/linux/regulator/consumer.h | 284 | ||||
-rw-r--r-- | include/linux/regulator/driver.h | 99 | ||||
-rw-r--r-- | include/linux/regulator/fixed.h | 22 | ||||
-rw-r--r-- | include/linux/regulator/machine.h | 104 |
19 files changed, 3956 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-regulator b/Documentation/ABI/testing/sysfs-class-regulator new file mode 100644 index 000000000000..79a4a75b2d2c --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-regulator | |||
@@ -0,0 +1,315 @@ | |||
1 | What: /sys/class/regulator/.../state | ||
2 | Date: April 2008 | ||
3 | KernelVersion: 2.6.26 | ||
4 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
5 | Description: | ||
6 | Each regulator directory will contain a field called | ||
7 | state. This holds the regulator output state. | ||
8 | |||
9 | This will be one of the following strings: | ||
10 | |||
11 | 'enabled' | ||
12 | 'disabled' | ||
13 | 'unknown' | ||
14 | |||
15 | 'enabled' means the regulator output is ON and is supplying | ||
16 | power to the system. | ||
17 | |||
18 | 'disabled' means the regulator output is OFF and is not | ||
19 | supplying power to the system.. | ||
20 | |||
21 | 'unknown' means software cannot determine the state. | ||
22 | |||
23 | NOTE: this field can be used in conjunction with microvolts | ||
24 | and microamps to determine regulator output levels. | ||
25 | |||
26 | |||
27 | What: /sys/class/regulator/.../type | ||
28 | Date: April 2008 | ||
29 | KernelVersion: 2.6.26 | ||
30 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
31 | Description: | ||
32 | Each regulator directory will contain a field called | ||
33 | type. This holds the regulator type. | ||
34 | |||
35 | This will be one of the following strings: | ||
36 | |||
37 | 'voltage' | ||
38 | 'current' | ||
39 | 'unknown' | ||
40 | |||
41 | 'voltage' means the regulator output voltage can be controlled | ||
42 | by software. | ||
43 | |||
44 | 'current' means the regulator output current limit can be | ||
45 | controlled by software. | ||
46 | |||
47 | 'unknown' means software cannot control either voltage or | ||
48 | current limit. | ||
49 | |||
50 | |||
51 | What: /sys/class/regulator/.../microvolts | ||
52 | Date: April 2008 | ||
53 | KernelVersion: 2.6.26 | ||
54 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
55 | Description: | ||
56 | Each regulator directory will contain a field called | ||
57 | microvolts. This holds the regulator output voltage setting | ||
58 | measured in microvolts (i.e. E-6 Volts). | ||
59 | |||
60 | NOTE: This value should not be used to determine the regulator | ||
61 | output voltage level as this value is the same regardless of | ||
62 | whether the regulator is enabled or disabled. | ||
63 | |||
64 | |||
65 | What: /sys/class/regulator/.../microamps | ||
66 | Date: April 2008 | ||
67 | KernelVersion: 2.6.26 | ||
68 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
69 | Description: | ||
70 | Each regulator directory will contain a field called | ||
71 | microamps. This holds the regulator output current limit | ||
72 | setting measured in microamps (i.e. E-6 Amps). | ||
73 | |||
74 | NOTE: This value should not be used to determine the regulator | ||
75 | output current level as this value is the same regardless of | ||
76 | whether the regulator is enabled or disabled. | ||
77 | |||
78 | |||
79 | What: /sys/class/regulator/.../opmode | ||
80 | Date: April 2008 | ||
81 | KernelVersion: 2.6.26 | ||
82 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
83 | Description: | ||
84 | Each regulator directory will contain a field called | ||
85 | opmode. This holds the regulator operating mode setting. | ||
86 | |||
87 | The opmode value can be one of the following strings: | ||
88 | |||
89 | 'fast' | ||
90 | 'normal' | ||
91 | 'idle' | ||
92 | 'standby' | ||
93 | 'unknown' | ||
94 | |||
95 | The modes are described in include/linux/regulator/regulator.h | ||
96 | |||
97 | NOTE: This value should not be used to determine the regulator | ||
98 | output operating mode as this value is the same regardless of | ||
99 | whether the regulator is enabled or disabled. | ||
100 | |||
101 | |||
102 | What: /sys/class/regulator/.../min_microvolts | ||
103 | Date: April 2008 | ||
104 | KernelVersion: 2.6.26 | ||
105 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
106 | Description: | ||
107 | Each regulator directory will contain a field called | ||
108 | min_microvolts. This holds the minimum safe working regulator | ||
109 | output voltage setting for this domain measured in microvolts. | ||
110 | |||
111 | NOTE: this will return the string 'constraint not defined' if | ||
112 | the power domain has no min microvolts constraint defined by | ||
113 | platform code. | ||
114 | |||
115 | |||
116 | What: /sys/class/regulator/.../max_microvolts | ||
117 | Date: April 2008 | ||
118 | KernelVersion: 2.6.26 | ||
119 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
120 | Description: | ||
121 | Each regulator directory will contain a field called | ||
122 | max_microvolts. This holds the maximum safe working regulator | ||
123 | output voltage setting for this domain measured in microvolts. | ||
124 | |||
125 | NOTE: this will return the string 'constraint not defined' if | ||
126 | the power domain has no max microvolts constraint defined by | ||
127 | platform code. | ||
128 | |||
129 | |||
130 | What: /sys/class/regulator/.../min_microamps | ||
131 | Date: April 2008 | ||
132 | KernelVersion: 2.6.26 | ||
133 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
134 | Description: | ||
135 | Each regulator directory will contain a field called | ||
136 | min_microamps. This holds the minimum safe working regulator | ||
137 | output current limit setting for this domain measured in | ||
138 | microamps. | ||
139 | |||
140 | NOTE: this will return the string 'constraint not defined' if | ||
141 | the power domain has no min microamps constraint defined by | ||
142 | platform code. | ||
143 | |||
144 | |||
145 | What: /sys/class/regulator/.../max_microamps | ||
146 | Date: April 2008 | ||
147 | KernelVersion: 2.6.26 | ||
148 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
149 | Description: | ||
150 | Each regulator directory will contain a field called | ||
151 | max_microamps. This holds the maximum safe working regulator | ||
152 | output current limit setting for this domain measured in | ||
153 | microamps. | ||
154 | |||
155 | NOTE: this will return the string 'constraint not defined' if | ||
156 | the power domain has no max microamps constraint defined by | ||
157 | platform code. | ||
158 | |||
159 | |||
160 | What: /sys/class/regulator/.../num_users | ||
161 | Date: April 2008 | ||
162 | KernelVersion: 2.6.26 | ||
163 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
164 | Description: | ||
165 | Each regulator directory will contain a field called | ||
166 | num_users. This holds the number of consumer devices that | ||
167 | have called regulator_enable() on this regulator. | ||
168 | |||
169 | |||
170 | What: /sys/class/regulator/.../requested_microamps | ||
171 | Date: April 2008 | ||
172 | KernelVersion: 2.6.26 | ||
173 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
174 | Description: | ||
175 | Each regulator directory will contain a field called | ||
176 | requested_microamps. This holds the total requested load | ||
177 | current in microamps for this regulator from all its consumer | ||
178 | devices. | ||
179 | |||
180 | |||
181 | What: /sys/class/regulator/.../parent | ||
182 | Date: April 2008 | ||
183 | KernelVersion: 2.6.26 | ||
184 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
185 | Description: | ||
186 | Some regulator directories will contain a link called parent. | ||
187 | This points to the parent or supply regulator if one exists. | ||
188 | |||
189 | What: /sys/class/regulator/.../suspend_mem_microvolts | ||
190 | Date: May 2008 | ||
191 | KernelVersion: 2.6.26 | ||
192 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
193 | Description: | ||
194 | Each regulator directory will contain a field called | ||
195 | suspend_mem_microvolts. This holds the regulator output | ||
196 | voltage setting for this domain measured in microvolts when | ||
197 | the system is suspended to memory. | ||
198 | |||
199 | NOTE: this will return the string 'not defined' if | ||
200 | the power domain has no suspend to memory voltage defined by | ||
201 | platform code. | ||
202 | |||
203 | What: /sys/class/regulator/.../suspend_disk_microvolts | ||
204 | Date: May 2008 | ||
205 | KernelVersion: 2.6.26 | ||
206 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
207 | Description: | ||
208 | Each regulator directory will contain a field called | ||
209 | suspend_disk_microvolts. This holds the regulator output | ||
210 | voltage setting for this domain measured in microvolts when | ||
211 | the system is suspended to disk. | ||
212 | |||
213 | NOTE: this will return the string 'not defined' if | ||
214 | the power domain has no suspend to disk voltage defined by | ||
215 | platform code. | ||
216 | |||
217 | What: /sys/class/regulator/.../suspend_standby_microvolts | ||
218 | Date: May 2008 | ||
219 | KernelVersion: 2.6.26 | ||
220 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
221 | Description: | ||
222 | Each regulator directory will contain a field called | ||
223 | suspend_standby_microvolts. This holds the regulator output | ||
224 | voltage setting for this domain measured in microvolts when | ||
225 | the system is suspended to standby. | ||
226 | |||
227 | NOTE: this will return the string 'not defined' if | ||
228 | the power domain has no suspend to standby voltage defined by | ||
229 | platform code. | ||
230 | |||
231 | What: /sys/class/regulator/.../suspend_mem_mode | ||
232 | Date: May 2008 | ||
233 | KernelVersion: 2.6.26 | ||
234 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
235 | Description: | ||
236 | Each regulator directory will contain a field called | ||
237 | suspend_mem_mode. This holds the regulator operating mode | ||
238 | setting for this domain when the system is suspended to | ||
239 | memory. | ||
240 | |||
241 | NOTE: this will return the string 'not defined' if | ||
242 | the power domain has no suspend to memory mode defined by | ||
243 | platform code. | ||
244 | |||
245 | What: /sys/class/regulator/.../suspend_disk_mode | ||
246 | Date: May 2008 | ||
247 | KernelVersion: 2.6.26 | ||
248 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
249 | Description: | ||
250 | Each regulator directory will contain a field called | ||
251 | suspend_disk_mode. This holds the regulator operating mode | ||
252 | setting for this domain when the system is suspended to disk. | ||
253 | |||
254 | NOTE: this will return the string 'not defined' if | ||
255 | the power domain has no suspend to disk mode defined by | ||
256 | platform code. | ||
257 | |||
258 | What: /sys/class/regulator/.../suspend_standby_mode | ||
259 | Date: May 2008 | ||
260 | KernelVersion: 2.6.26 | ||
261 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
262 | Description: | ||
263 | Each regulator directory will contain a field called | ||
264 | suspend_standby_mode. This holds the regulator operating mode | ||
265 | setting for this domain when the system is suspended to | ||
266 | standby. | ||
267 | |||
268 | NOTE: this will return the string 'not defined' if | ||
269 | the power domain has no suspend to standby mode defined by | ||
270 | platform code. | ||
271 | |||
272 | What: /sys/class/regulator/.../suspend_mem_state | ||
273 | Date: May 2008 | ||
274 | KernelVersion: 2.6.26 | ||
275 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
276 | Description: | ||
277 | Each regulator directory will contain a field called | ||
278 | suspend_mem_state. This holds the regulator operating state | ||
279 | when suspended to memory. | ||
280 | |||
281 | This will be one of the following strings: | ||
282 | |||
283 | 'enabled' | ||
284 | 'disabled' | ||
285 | 'not defined' | ||
286 | |||
287 | What: /sys/class/regulator/.../suspend_disk_state | ||
288 | Date: May 2008 | ||
289 | KernelVersion: 2.6.26 | ||
290 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
291 | Description: | ||
292 | Each regulator directory will contain a field called | ||
293 | suspend_disk_state. This holds the regulator operating state | ||
294 | when suspended to disk. | ||
295 | |||
296 | This will be one of the following strings: | ||
297 | |||
298 | 'enabled' | ||
299 | 'disabled' | ||
300 | 'not defined' | ||
301 | |||
302 | What: /sys/class/regulator/.../suspend_standby_state | ||
303 | Date: May 2008 | ||
304 | KernelVersion: 2.6.26 | ||
305 | Contact: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
306 | Description: | ||
307 | Each regulator directory will contain a field called | ||
308 | suspend_standby_state. This holds the regulator operating | ||
309 | state when suspended to standby. | ||
310 | |||
311 | This will be one of the following strings: | ||
312 | |||
313 | 'enabled' | ||
314 | 'disabled' | ||
315 | 'not defined' | ||
diff --git a/Documentation/power/regulator/consumer.txt b/Documentation/power/regulator/consumer.txt new file mode 100644 index 000000000000..82b7a43aadba --- /dev/null +++ b/Documentation/power/regulator/consumer.txt | |||
@@ -0,0 +1,182 @@ | |||
1 | Regulator Consumer Driver Interface | ||
2 | =================================== | ||
3 | |||
4 | This text describes the regulator interface for consumer device drivers. | ||
5 | Please see overview.txt for a description of the terms used in this text. | ||
6 | |||
7 | |||
8 | 1. Consumer Regulator Access (static & dynamic drivers) | ||
9 | ======================================================= | ||
10 | |||
11 | A consumer driver can get access to it's supply regulator by calling :- | ||
12 | |||
13 | regulator = regulator_get(dev, "Vcc"); | ||
14 | |||
15 | The consumer passes in it's struct device pointer and power supply ID. The core | ||
16 | then finds the correct regulator by consulting a machine specific lookup table. | ||
17 | If the lookup is successful then this call will return a pointer to the struct | ||
18 | regulator that supplies this consumer. | ||
19 | |||
20 | To release the regulator the consumer driver should call :- | ||
21 | |||
22 | regulator_put(regulator); | ||
23 | |||
24 | Consumers can be supplied by more than one regulator e.g. codec consumer with | ||
25 | analog and digital supplies :- | ||
26 | |||
27 | digital = regulator_get(dev, "Vcc"); /* digital core */ | ||
28 | analog = regulator_get(dev, "Avdd"); /* analog */ | ||
29 | |||
30 | The regulator access functions regulator_get() and regulator_put() will | ||
31 | usually be called in your device drivers probe() and remove() respectively. | ||
32 | |||
33 | |||
34 | 2. Regulator Output Enable & Disable (static & dynamic drivers) | ||
35 | ==================================================================== | ||
36 | |||
37 | A consumer can enable it's power supply by calling:- | ||
38 | |||
39 | int regulator_enable(regulator); | ||
40 | |||
41 | NOTE: The supply may already be enabled before regulator_enabled() is called. | ||
42 | This may happen if the consumer shares the regulator or the regulator has been | ||
43 | previously enabled by bootloader or kernel board initialization code. | ||
44 | |||
45 | A consumer can determine if a regulator is enabled by calling :- | ||
46 | |||
47 | int regulator_is_enabled(regulator); | ||
48 | |||
49 | This will return > zero when the regulator is enabled. | ||
50 | |||
51 | |||
52 | A consumer can disable it's supply when no longer needed by calling :- | ||
53 | |||
54 | int regulator_disable(regulator); | ||
55 | |||
56 | NOTE: This may not disable the supply if it's shared with other consumers. The | ||
57 | regulator will only be disabled when the enabled reference count is zero. | ||
58 | |||
59 | Finally, a regulator can be forcefully disabled in the case of an emergency :- | ||
60 | |||
61 | int regulator_force_disable(regulator); | ||
62 | |||
63 | NOTE: this will immediately and forcefully shutdown the regulator output. All | ||
64 | consumers will be powered off. | ||
65 | |||
66 | |||
67 | 3. Regulator Voltage Control & Status (dynamic drivers) | ||
68 | ====================================================== | ||
69 | |||
70 | Some consumer drivers need to be able to dynamically change their supply | ||
71 | voltage to match system operating points. e.g. CPUfreq drivers can scale | ||
72 | voltage along with frequency to save power, SD drivers may need to select the | ||
73 | correct card voltage, etc. | ||
74 | |||
75 | Consumers can control their supply voltage by calling :- | ||
76 | |||
77 | int regulator_set_voltage(regulator, min_uV, max_uV); | ||
78 | |||
79 | Where min_uV and max_uV are the minimum and maximum acceptable voltages in | ||
80 | microvolts. | ||
81 | |||
82 | NOTE: this can be called when the regulator is enabled or disabled. If called | ||
83 | when enabled, then the voltage changes instantly, otherwise the voltage | ||
84 | configuration changes and the voltage is physically set when the regulator is | ||
85 | next enabled. | ||
86 | |||
87 | The regulators configured voltage output can be found by calling :- | ||
88 | |||
89 | int regulator_get_voltage(regulator); | ||
90 | |||
91 | NOTE: get_voltage() will return the configured output voltage whether the | ||
92 | regulator is enabled or disabled and should NOT be used to determine regulator | ||
93 | output state. However this can be used in conjunction with is_enabled() to | ||
94 | determine the regulator physical output voltage. | ||
95 | |||
96 | |||
97 | 4. Regulator Current Limit Control & Status (dynamic drivers) | ||
98 | =========================================================== | ||
99 | |||
100 | Some consumer drivers need to be able to dynamically change their supply | ||
101 | current limit to match system operating points. e.g. LCD backlight driver can | ||
102 | change the current limit to vary the backlight brightness, USB drivers may want | ||
103 | to set the limit to 500mA when supplying power. | ||
104 | |||
105 | Consumers can control their supply current limit by calling :- | ||
106 | |||
107 | int regulator_set_current_limit(regulator, min_uV, max_uV); | ||
108 | |||
109 | Where min_uA and max_uA are the minimum and maximum acceptable current limit in | ||
110 | microamps. | ||
111 | |||
112 | NOTE: this can be called when the regulator is enabled or disabled. If called | ||
113 | when enabled, then the current limit changes instantly, otherwise the current | ||
114 | limit configuration changes and the current limit is physically set when the | ||
115 | regulator is next enabled. | ||
116 | |||
117 | A regulators current limit can be found by calling :- | ||
118 | |||
119 | int regulator_get_current_limit(regulator); | ||
120 | |||
121 | NOTE: get_current_limit() will return the current limit whether the regulator | ||
122 | is enabled or disabled and should not be used to determine regulator current | ||
123 | load. | ||
124 | |||
125 | |||
126 | 5. Regulator Operating Mode Control & Status (dynamic drivers) | ||
127 | ============================================================= | ||
128 | |||
129 | Some consumers can further save system power by changing the operating mode of | ||
130 | their supply regulator to be more efficient when the consumers operating state | ||
131 | changes. e.g. consumer driver is idle and subsequently draws less current | ||
132 | |||
133 | Regulator operating mode can be changed indirectly or directly. | ||
134 | |||
135 | Indirect operating mode control. | ||
136 | -------------------------------- | ||
137 | Consumer drivers can request a change in their supply regulator operating mode | ||
138 | by calling :- | ||
139 | |||
140 | int regulator_set_optimum_mode(struct regulator *regulator, int load_uA); | ||
141 | |||
142 | This will cause the core to recalculate the total load on the regulator (based | ||
143 | on all it's consumers) and change operating mode (if necessary and permitted) | ||
144 | to best match the current operating load. | ||
145 | |||
146 | The load_uA value can be determined from the consumers datasheet. e.g.most | ||
147 | datasheets have tables showing the max current consumed in certain situations. | ||
148 | |||
149 | Most consumers will use indirect operating mode control since they have no | ||
150 | knowledge of the regulator or whether the regulator is shared with other | ||
151 | consumers. | ||
152 | |||
153 | Direct operating mode control. | ||
154 | ------------------------------ | ||
155 | Bespoke or tightly coupled drivers may want to directly control regulator | ||
156 | operating mode depending on their operating point. This can be achieved by | ||
157 | calling :- | ||
158 | |||
159 | int regulator_set_mode(struct regulator *regulator, unsigned int mode); | ||
160 | unsigned int regulator_get_mode(struct regulator *regulator); | ||
161 | |||
162 | Direct mode will only be used by consumers that *know* about the regulator and | ||
163 | are not sharing the regulator with other consumers. | ||
164 | |||
165 | |||
166 | 6. Regulator Events | ||
167 | =================== | ||
168 | Regulators can notify consumers of external events. Events could be received by | ||
169 | consumers under regulator stress or failure conditions. | ||
170 | |||
171 | Consumers can register interest in regulator events by calling :- | ||
172 | |||
173 | int regulator_register_notifier(struct regulator *regulator, | ||
174 | struct notifier_block *nb); | ||
175 | |||
176 | Consumers can uregister interest by calling :- | ||
177 | |||
178 | int regulator_unregister_notifier(struct regulator *regulator, | ||
179 | struct notifier_block *nb); | ||
180 | |||
181 | Regulators use the kernel notifier framework to send event to thier interested | ||
182 | consumers. | ||
diff --git a/Documentation/power/regulator/machine.txt b/Documentation/power/regulator/machine.txt new file mode 100644 index 000000000000..c9a35665cf70 --- /dev/null +++ b/Documentation/power/regulator/machine.txt | |||
@@ -0,0 +1,101 @@ | |||
1 | Regulator Machine Driver Interface | ||
2 | =================================== | ||
3 | |||
4 | The regulator machine driver interface is intended for board/machine specific | ||
5 | initialisation code to configure the regulator subsystem. Typical things that | ||
6 | machine drivers would do are :- | ||
7 | |||
8 | 1. Regulator -> Device mapping. | ||
9 | 2. Regulator supply configuration. | ||
10 | 3. Power Domain constraint setting. | ||
11 | |||
12 | |||
13 | |||
14 | 1. Regulator -> device mapping | ||
15 | ============================== | ||
16 | Consider the following machine :- | ||
17 | |||
18 | Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V] | ||
19 | | | ||
20 | +-> [Consumer B @ 3.3V] | ||
21 | |||
22 | The drivers for consumers A & B must be mapped to the correct regulator in | ||
23 | order to control their power supply. This mapping can be achieved in machine | ||
24 | initialisation code by calling :- | ||
25 | |||
26 | int regulator_set_device_supply(const char *regulator, struct device *dev, | ||
27 | const char *supply); | ||
28 | |||
29 | and is shown with the following code :- | ||
30 | |||
31 | regulator_set_device_supply("Regulator-1", devB, "Vcc"); | ||
32 | regulator_set_device_supply("Regulator-2", devA, "Vcc"); | ||
33 | |||
34 | This maps Regulator-1 to the 'Vcc' supply for Consumer B and maps Regulator-2 | ||
35 | to the 'Vcc' supply for Consumer A. | ||
36 | |||
37 | |||
38 | 2. Regulator supply configuration. | ||
39 | ================================== | ||
40 | Consider the following machine (again) :- | ||
41 | |||
42 | Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V] | ||
43 | | | ||
44 | +-> [Consumer B @ 3.3V] | ||
45 | |||
46 | Regulator-1 supplies power to Regulator-2. This relationship must be registered | ||
47 | with the core so that Regulator-1 is also enabled when Consumer A enables it's | ||
48 | supply (Regulator-2). | ||
49 | |||
50 | This relationship can be register with the core via :- | ||
51 | |||
52 | int regulator_set_supply(const char *regulator, const char *regulator_supply); | ||
53 | |||
54 | In this example we would use the following code :- | ||
55 | |||
56 | regulator_set_supply("Regulator-2", "Regulator-1"); | ||
57 | |||
58 | Relationships can be queried by calling :- | ||
59 | |||
60 | const char *regulator_get_supply(const char *regulator); | ||
61 | |||
62 | |||
63 | 3. Power Domain constraint setting. | ||
64 | =================================== | ||
65 | Each power domain within a system has physical constraints on voltage and | ||
66 | current. This must be defined in software so that the power domain is always | ||
67 | operated within specifications. | ||
68 | |||
69 | Consider the following machine (again) :- | ||
70 | |||
71 | Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V] | ||
72 | | | ||
73 | +-> [Consumer B @ 3.3V] | ||
74 | |||
75 | This gives us two regulators and two power domains: | ||
76 | |||
77 | Domain 1: Regulator-2, Consumer B. | ||
78 | Domain 2: Consumer A. | ||
79 | |||
80 | Constraints can be registered by calling :- | ||
81 | |||
82 | int regulator_set_platform_constraints(const char *regulator, | ||
83 | struct regulation_constraints *constraints); | ||
84 | |||
85 | The example is defined as follows :- | ||
86 | |||
87 | struct regulation_constraints domain_1 = { | ||
88 | .min_uV = 3300000, | ||
89 | .max_uV = 3300000, | ||
90 | .valid_modes_mask = REGULATOR_MODE_NORMAL, | ||
91 | }; | ||
92 | |||
93 | struct regulation_constraints domain_2 = { | ||
94 | .min_uV = 1800000, | ||
95 | .max_uV = 2000000, | ||
96 | .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE, | ||
97 | .valid_modes_mask = REGULATOR_MODE_NORMAL, | ||
98 | }; | ||
99 | |||
100 | regulator_set_platform_constraints("Regulator-1", &domain_1); | ||
101 | regulator_set_platform_constraints("Regulator-2", &domain_2); | ||
diff --git a/Documentation/power/regulator/overview.txt b/Documentation/power/regulator/overview.txt new file mode 100644 index 000000000000..bdcb332bd7fb --- /dev/null +++ b/Documentation/power/regulator/overview.txt | |||
@@ -0,0 +1,171 @@ | |||
1 | Linux voltage and current regulator framework | ||
2 | ============================================= | ||
3 | |||
4 | About | ||
5 | ===== | ||
6 | |||
7 | This framework is designed to provide a standard kernel interface to control | ||
8 | voltage and current regulators. | ||
9 | |||
10 | The intention is to allow systems to dynamically control regulator power output | ||
11 | in order to save power and prolong battery life. This applies to both voltage | ||
12 | regulators (where voltage output is controllable) and current sinks (where | ||
13 | current limit is controllable). | ||
14 | |||
15 | (C) 2008 Wolfson Microelectronics PLC. | ||
16 | Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
17 | |||
18 | |||
19 | Nomenclature | ||
20 | ============ | ||
21 | |||
22 | Some terms used in this document:- | ||
23 | |||
24 | o Regulator - Electronic device that supplies power to other devices. | ||
25 | Most regulators can enable and disable their output whilst | ||
26 | some can control their output voltage and or current. | ||
27 | |||
28 | Input Voltage -> Regulator -> Output Voltage | ||
29 | |||
30 | |||
31 | o PMIC - Power Management IC. An IC that contains numerous regulators | ||
32 | and often contains other susbsystems. | ||
33 | |||
34 | |||
35 | o Consumer - Electronic device that is supplied power by a regulator. | ||
36 | Consumers can be classified into two types:- | ||
37 | |||
38 | Static: consumer does not change it's supply voltage or | ||
39 | current limit. It only needs to enable or disable it's | ||
40 | power supply. It's supply voltage is set by the hardware, | ||
41 | bootloader, firmware or kernel board initialisation code. | ||
42 | |||
43 | Dynamic: consumer needs to change it's supply voltage or | ||
44 | current limit to meet operation demands. | ||
45 | |||
46 | |||
47 | o Power Domain - Electronic circuit that is supplied it's input power by the | ||
48 | output power of a regulator, switch or by another power | ||
49 | domain. | ||
50 | |||
51 | The supply regulator may be behind a switch(s). i.e. | ||
52 | |||
53 | Regulator -+-> Switch-1 -+-> Switch-2 --> [Consumer A] | ||
54 | | | | ||
55 | | +-> [Consumer B], [Consumer C] | ||
56 | | | ||
57 | +-> [Consumer D], [Consumer E] | ||
58 | |||
59 | That is one regulator and three power domains: | ||
60 | |||
61 | Domain 1: Switch-1, Consumers D & E. | ||
62 | Domain 2: Switch-2, Consumers B & C. | ||
63 | Domain 3: Consumer A. | ||
64 | |||
65 | and this represents a "supplies" relationship: | ||
66 | |||
67 | Domain-1 --> Domain-2 --> Domain-3. | ||
68 | |||
69 | A power domain may have regulators that are supplied power | ||
70 | by other regulators. i.e. | ||
71 | |||
72 | Regulator-1 -+-> Regulator-2 -+-> [Consumer A] | ||
73 | | | ||
74 | +-> [Consumer B] | ||
75 | |||
76 | This gives us two regulators and two power domains: | ||
77 | |||
78 | Domain 1: Regulator-2, Consumer B. | ||
79 | Domain 2: Consumer A. | ||
80 | |||
81 | and a "supplies" relationship: | ||
82 | |||
83 | Domain-1 --> Domain-2 | ||
84 | |||
85 | |||
86 | o Constraints - Constraints are used to define power levels for performance | ||
87 | and hardware protection. Constraints exist at three levels: | ||
88 | |||
89 | Regulator Level: This is defined by the regulator hardware | ||
90 | operating parameters and is specified in the regulator | ||
91 | datasheet. i.e. | ||
92 | |||
93 | - voltage output is in the range 800mV -> 3500mV. | ||
94 | - regulator current output limit is 20mA @ 5V but is | ||
95 | 10mA @ 10V. | ||
96 | |||
97 | Power Domain Level: This is defined in software by kernel | ||
98 | level board initialisation code. It is used to constrain a | ||
99 | power domain to a particular power range. i.e. | ||
100 | |||
101 | - Domain-1 voltage is 3300mV | ||
102 | - Domain-2 voltage is 1400mV -> 1600mV | ||
103 | - Domain-3 current limit is 0mA -> 20mA. | ||
104 | |||
105 | Consumer Level: This is defined by consumer drivers | ||
106 | dynamically setting voltage or current limit levels. | ||
107 | |||
108 | e.g. a consumer backlight driver asks for a current increase | ||
109 | from 5mA to 10mA to increase LCD illumination. This passes | ||
110 | to through the levels as follows :- | ||
111 | |||
112 | Consumer: need to increase LCD brightness. Lookup and | ||
113 | request next current mA value in brightness table (the | ||
114 | consumer driver could be used on several different | ||
115 | personalities based upon the same reference device). | ||
116 | |||
117 | Power Domain: is the new current limit within the domain | ||
118 | operating limits for this domain and system state (e.g. | ||
119 | battery power, USB power) | ||
120 | |||
121 | Regulator Domains: is the new current limit within the | ||
122 | regulator operating parameters for input/ouput voltage. | ||
123 | |||
124 | If the regulator request passes all the constraint tests | ||
125 | then the new regulator value is applied. | ||
126 | |||
127 | |||
128 | Design | ||
129 | ====== | ||
130 | |||
131 | The framework is designed and targeted at SoC based devices but may also be | ||
132 | relevant to non SoC devices and is split into the following four interfaces:- | ||
133 | |||
134 | |||
135 | 1. Consumer driver interface. | ||
136 | |||
137 | This uses a similar API to the kernel clock interface in that consumer | ||
138 | drivers can get and put a regulator (like they can with clocks atm) and | ||
139 | get/set voltage, current limit, mode, enable and disable. This should | ||
140 | allow consumers complete control over their supply voltage and current | ||
141 | limit. This also compiles out if not in use so drivers can be reused in | ||
142 | systems with no regulator based power control. | ||
143 | |||
144 | See Documentation/power/regulator/consumer.txt | ||
145 | |||
146 | 2. Regulator driver interface. | ||
147 | |||
148 | This allows regulator drivers to register their regulators and provide | ||
149 | operations to the core. It also has a notifier call chain for propagating | ||
150 | regulator events to clients. | ||
151 | |||
152 | See Documentation/power/regulator/regulator.txt | ||
153 | |||
154 | 3. Machine interface. | ||
155 | |||
156 | This interface is for machine specific code and allows the creation of | ||
157 | voltage/current domains (with constraints) for each regulator. It can | ||
158 | provide regulator constraints that will prevent device damage through | ||
159 | overvoltage or over current caused by buggy client drivers. It also | ||
160 | allows the creation of a regulator tree whereby some regulators are | ||
161 | supplied by others (similar to a clock tree). | ||
162 | |||
163 | See Documentation/power/regulator/machine.txt | ||
164 | |||
165 | 4. Userspace ABI. | ||
166 | |||
167 | The framework also exports a lot of useful voltage/current/opmode data to | ||
168 | userspace via sysfs. This could be used to help monitor device power | ||
169 | consumption and status. | ||
170 | |||
171 | See Documentation/ABI/testing/regulator-sysfs.txt | ||
diff --git a/Documentation/power/regulator/regulator.txt b/Documentation/power/regulator/regulator.txt new file mode 100644 index 000000000000..a69050143592 --- /dev/null +++ b/Documentation/power/regulator/regulator.txt | |||
@@ -0,0 +1,30 @@ | |||
1 | Regulator Driver Interface | ||
2 | ========================== | ||
3 | |||
4 | The regulator driver interface is relatively simple and designed to allow | ||
5 | regulator drivers to register their services with the core framework. | ||
6 | |||
7 | |||
8 | Registration | ||
9 | ============ | ||
10 | |||
11 | Drivers can register a regulator by calling :- | ||
12 | |||
13 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | ||
14 | void *reg_data); | ||
15 | |||
16 | This will register the regulators capabilities and operations the regulator | ||
17 | core. The core does not touch reg_data (private to regulator driver). | ||
18 | |||
19 | Regulators can be unregistered by calling :- | ||
20 | |||
21 | void regulator_unregister(struct regulator_dev *rdev); | ||
22 | |||
23 | |||
24 | Regulator Events | ||
25 | ================ | ||
26 | Regulators can send events (e.g. over temp, under voltage, etc) to consumer | ||
27 | drivers by calling :- | ||
28 | |||
29 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | ||
30 | unsigned long event, void *data); | ||
diff --git a/MAINTAINERS b/MAINTAINERS index 5f043d19cedc..c65a5b9e3446 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -4504,6 +4504,15 @@ M: kaber@trash.net | |||
4504 | L: netdev@vger.kernel.org | 4504 | L: netdev@vger.kernel.org |
4505 | S: Maintained | 4505 | S: Maintained |
4506 | 4506 | ||
4507 | VOLTAGE AND CURRENT REGULATOR FRAMEWORK | ||
4508 | P: Liam Girdwood | ||
4509 | M: lg@opensource.wolfsonmicro.com | ||
4510 | P: Mark Brown | ||
4511 | M: broonie@opensource.wolfsonmicro.com | ||
4512 | W: http://opensource.wolfsonmicro.com/node/15 | ||
4513 | T: git kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6.git | ||
4514 | S: Supported | ||
4515 | |||
4507 | VT1211 HARDWARE MONITOR DRIVER | 4516 | VT1211 HARDWARE MONITOR DRIVER |
4508 | P: Juerg Haefliger | 4517 | P: Juerg Haefliger |
4509 | M: juergh@gmail.com | 4518 | M: juergh@gmail.com |
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 257033c691f2..4b8acd2851f4 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig | |||
@@ -1225,6 +1225,8 @@ source "drivers/dma/Kconfig" | |||
1225 | 1225 | ||
1226 | source "drivers/dca/Kconfig" | 1226 | source "drivers/dca/Kconfig" |
1227 | 1227 | ||
1228 | source "drivers/regulator/Kconfig" | ||
1229 | |||
1228 | source "drivers/uio/Kconfig" | 1230 | source "drivers/uio/Kconfig" |
1229 | 1231 | ||
1230 | endmenu | 1232 | endmenu |
diff --git a/drivers/Makefile b/drivers/Makefile index 54ec5e718c0e..a280ab3d0833 100644 --- a/drivers/Makefile +++ b/drivers/Makefile | |||
@@ -97,3 +97,4 @@ obj-$(CONFIG_PPC_PS3) += ps3/ | |||
97 | obj-$(CONFIG_OF) += of/ | 97 | obj-$(CONFIG_OF) += of/ |
98 | obj-$(CONFIG_SSB) += ssb/ | 98 | obj-$(CONFIG_SSB) += ssb/ |
99 | obj-$(CONFIG_VIRTIO) += virtio/ | 99 | obj-$(CONFIG_VIRTIO) += virtio/ |
100 | obj-$(CONFIG_REGULATOR) += regulator/ | ||
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig new file mode 100644 index 000000000000..a656128f1fdd --- /dev/null +++ b/drivers/regulator/Kconfig | |||
@@ -0,0 +1,59 @@ | |||
1 | menu "Voltage and Current regulators" | ||
2 | |||
3 | config REGULATOR | ||
4 | bool "Voltage and Current Regulator Support" | ||
5 | default n | ||
6 | help | ||
7 | Generic Voltage and Current Regulator support. | ||
8 | |||
9 | This framework is designed to provide a generic interface to voltage | ||
10 | and current regulators within the Linux kernel. It's intended to | ||
11 | provide voltage and current control to client or consumer drivers and | ||
12 | also provide status information to user space applications through a | ||
13 | sysfs interface. | ||
14 | |||
15 | The intention is to allow systems to dynamically control regulator | ||
16 | output in order to save power and prolong battery life. This applies | ||
17 | to both voltage regulators (where voltage output is controllable) and | ||
18 | current sinks (where current output is controllable). | ||
19 | |||
20 | This framework safely compiles out if not selected so that client | ||
21 | drivers can still be used in systems with no software controllable | ||
22 | regulators. | ||
23 | |||
24 | If unsure, say no. | ||
25 | |||
26 | config REGULATOR_DEBUG | ||
27 | bool "Regulator debug support" | ||
28 | depends on REGULATOR | ||
29 | help | ||
30 | Say yes here to enable debugging support. | ||
31 | |||
32 | config REGULATOR_FIXED_VOLTAGE | ||
33 | tristate | ||
34 | default n | ||
35 | select REGULATOR | ||
36 | |||
37 | config REGULATOR_VIRTUAL_CONSUMER | ||
38 | tristate "Virtual regulator consumer support" | ||
39 | default n | ||
40 | select REGULATOR | ||
41 | help | ||
42 | This driver provides a virtual consumer for the voltage and | ||
43 | current regulator API which provides sysfs controls for | ||
44 | configuring the supplies requested. This is mainly useful | ||
45 | for test purposes. | ||
46 | |||
47 | If unsure, say no. | ||
48 | |||
49 | config REGULATOR_BQ24022 | ||
50 | tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" | ||
51 | default n | ||
52 | select REGULATOR | ||
53 | help | ||
54 | This driver controls a TI bq24022 Charger attached via | ||
55 | GPIOs. The provided current regulator can enable/disable | ||
56 | charging select between 100 mA and 500 mA charging current | ||
57 | limit. | ||
58 | |||
59 | endmenu | ||
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile new file mode 100644 index 000000000000..ac2c64efe65c --- /dev/null +++ b/drivers/regulator/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | # | ||
2 | # Makefile for regulator drivers. | ||
3 | # | ||
4 | |||
5 | |||
6 | obj-$(CONFIG_REGULATOR) += core.o | ||
7 | obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o | ||
8 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o | ||
9 | |||
10 | obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o | ||
11 | |||
12 | ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG | ||
diff --git a/drivers/regulator/bq24022.c b/drivers/regulator/bq24022.c new file mode 100644 index 000000000000..263699d6152d --- /dev/null +++ b/drivers/regulator/bq24022.c | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | * Support for TI bq24022 (bqTINY-II) Dual Input (USB/AC Adpater) | ||
3 | * 1-Cell Li-Ion Charger connected via GPIOs. | ||
4 | * | ||
5 | * Copyright (c) 2008 Philipp Zabel | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/gpio.h> | ||
18 | #include <linux/regulator/bq24022.h> | ||
19 | #include <linux/regulator/driver.h> | ||
20 | |||
21 | static int bq24022_set_current_limit(struct regulator_dev *rdev, | ||
22 | int min_uA, int max_uA) | ||
23 | { | ||
24 | struct platform_device *pdev = rdev_get_drvdata(rdev); | ||
25 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
26 | |||
27 | dev_dbg(&pdev->dev, "setting current limit to %s mA\n", | ||
28 | max_uA >= 500000 ? "500" : "100"); | ||
29 | |||
30 | /* REVISIT: maybe return error if min_uA != 0 ? */ | ||
31 | gpio_set_value(pdata->gpio_iset2, max_uA >= 500000); | ||
32 | return 0; | ||
33 | } | ||
34 | |||
35 | static int bq24022_get_current_limit(struct regulator_dev *rdev) | ||
36 | { | ||
37 | struct platform_device *pdev = rdev_get_drvdata(rdev); | ||
38 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
39 | |||
40 | return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000; | ||
41 | } | ||
42 | |||
43 | static int bq24022_enable(struct regulator_dev *rdev) | ||
44 | { | ||
45 | struct platform_device *pdev = rdev_get_drvdata(rdev); | ||
46 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
47 | |||
48 | dev_dbg(&pdev->dev, "enabling charger\n"); | ||
49 | |||
50 | gpio_set_value(pdata->gpio_nce, 0); | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | static int bq24022_disable(struct regulator_dev *rdev) | ||
55 | { | ||
56 | struct platform_device *pdev = rdev_get_drvdata(rdev); | ||
57 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
58 | |||
59 | dev_dbg(&pdev->dev, "disabling charger\n"); | ||
60 | |||
61 | gpio_set_value(pdata->gpio_nce, 1); | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static int bq24022_is_enabled(struct regulator_dev *rdev) | ||
66 | { | ||
67 | struct platform_device *pdev = rdev_get_drvdata(rdev); | ||
68 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
69 | |||
70 | return !gpio_get_value(pdata->gpio_nce); | ||
71 | } | ||
72 | |||
73 | static struct regulator_ops bq24022_ops = { | ||
74 | .set_current_limit = bq24022_set_current_limit, | ||
75 | .get_current_limit = bq24022_get_current_limit, | ||
76 | .enable = bq24022_enable, | ||
77 | .disable = bq24022_disable, | ||
78 | .is_enabled = bq24022_is_enabled, | ||
79 | }; | ||
80 | |||
81 | static struct regulator_desc bq24022_desc = { | ||
82 | .name = "bq24022", | ||
83 | .ops = &bq24022_ops, | ||
84 | .type = REGULATOR_CURRENT, | ||
85 | }; | ||
86 | |||
87 | static int __init bq24022_probe(struct platform_device *pdev) | ||
88 | { | ||
89 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
90 | struct regulator_dev *bq24022; | ||
91 | int ret; | ||
92 | |||
93 | if (!pdata || !pdata->gpio_nce || !pdata->gpio_iset2) | ||
94 | return -EINVAL; | ||
95 | |||
96 | ret = gpio_request(pdata->gpio_nce, "ncharge_en"); | ||
97 | if (ret) { | ||
98 | dev_dbg(&pdev->dev, "couldn't request nCE GPIO: %d\n", | ||
99 | pdata->gpio_nce); | ||
100 | goto err_ce; | ||
101 | } | ||
102 | ret = gpio_request(pdata->gpio_iset2, "charge_mode"); | ||
103 | if (ret) { | ||
104 | dev_dbg(&pdev->dev, "couldn't request ISET2 GPIO: %d\n", | ||
105 | pdata->gpio_iset2); | ||
106 | goto err_iset2; | ||
107 | } | ||
108 | ret = gpio_direction_output(pdata->gpio_iset2, 0); | ||
109 | ret = gpio_direction_output(pdata->gpio_nce, 1); | ||
110 | |||
111 | bq24022 = regulator_register(&bq24022_desc, pdev); | ||
112 | if (IS_ERR(bq24022)) { | ||
113 | dev_dbg(&pdev->dev, "couldn't register regulator\n"); | ||
114 | ret = PTR_ERR(bq24022); | ||
115 | goto err_reg; | ||
116 | } | ||
117 | platform_set_drvdata(pdev, bq24022); | ||
118 | dev_dbg(&pdev->dev, "registered regulator\n"); | ||
119 | |||
120 | return 0; | ||
121 | err_reg: | ||
122 | gpio_free(pdata->gpio_iset2); | ||
123 | err_iset2: | ||
124 | gpio_free(pdata->gpio_nce); | ||
125 | err_ce: | ||
126 | return ret; | ||
127 | } | ||
128 | |||
129 | static int __devexit bq24022_remove(struct platform_device *pdev) | ||
130 | { | ||
131 | struct bq24022_mach_info *pdata = pdev->dev.platform_data; | ||
132 | struct regulator_dev *bq24022 = platform_get_drvdata(pdev); | ||
133 | |||
134 | regulator_unregister(bq24022); | ||
135 | gpio_free(pdata->gpio_iset2); | ||
136 | gpio_free(pdata->gpio_nce); | ||
137 | |||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | static struct platform_driver bq24022_driver = { | ||
142 | .driver = { | ||
143 | .name = "bq24022", | ||
144 | }, | ||
145 | .remove = __devexit_p(bq24022_remove), | ||
146 | }; | ||
147 | |||
148 | static int __init bq24022_init(void) | ||
149 | { | ||
150 | return platform_driver_probe(&bq24022_driver, bq24022_probe); | ||
151 | } | ||
152 | |||
153 | static void __exit bq24022_exit(void) | ||
154 | { | ||
155 | platform_driver_unregister(&bq24022_driver); | ||
156 | } | ||
157 | |||
158 | /* | ||
159 | * make sure this is probed before gpio_vbus and pda_power, | ||
160 | * but after asic3 or other GPIO expander drivers. | ||
161 | */ | ||
162 | subsys_initcall(bq24022_init); | ||
163 | module_exit(bq24022_exit); | ||
164 | |||
165 | MODULE_AUTHOR("Philipp Zabel"); | ||
166 | MODULE_DESCRIPTION("TI bq24022 Li-Ion Charger driver"); | ||
167 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c new file mode 100644 index 000000000000..9c7986261568 --- /dev/null +++ b/drivers/regulator/core.c | |||
@@ -0,0 +1,1903 @@ | |||
1 | /* | ||
2 | * core.c -- Voltage/Current Regulator framework. | ||
3 | * | ||
4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/device.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/mutex.h> | ||
20 | #include <linux/suspend.h> | ||
21 | #include <linux/regulator/consumer.h> | ||
22 | #include <linux/regulator/driver.h> | ||
23 | #include <linux/regulator/machine.h> | ||
24 | |||
25 | #define REGULATOR_VERSION "0.5" | ||
26 | |||
27 | static DEFINE_MUTEX(regulator_list_mutex); | ||
28 | static LIST_HEAD(regulator_list); | ||
29 | static LIST_HEAD(regulator_map_list); | ||
30 | |||
31 | /** | ||
32 | * struct regulator_dev | ||
33 | * | ||
34 | * Voltage / Current regulator class device. One for each regulator. | ||
35 | */ | ||
36 | struct regulator_dev { | ||
37 | struct regulator_desc *desc; | ||
38 | int use_count; | ||
39 | |||
40 | /* lists we belong to */ | ||
41 | struct list_head list; /* list of all regulators */ | ||
42 | struct list_head slist; /* list of supplied regulators */ | ||
43 | |||
44 | /* lists we own */ | ||
45 | struct list_head consumer_list; /* consumers we supply */ | ||
46 | struct list_head supply_list; /* regulators we supply */ | ||
47 | |||
48 | struct blocking_notifier_head notifier; | ||
49 | struct mutex mutex; /* consumer lock */ | ||
50 | struct module *owner; | ||
51 | struct device dev; | ||
52 | struct regulation_constraints *constraints; | ||
53 | struct regulator_dev *supply; /* for tree */ | ||
54 | |||
55 | void *reg_data; /* regulator_dev data */ | ||
56 | }; | ||
57 | |||
58 | /** | ||
59 | * struct regulator_map | ||
60 | * | ||
61 | * Used to provide symbolic supply names to devices. | ||
62 | */ | ||
63 | struct regulator_map { | ||
64 | struct list_head list; | ||
65 | struct device *dev; | ||
66 | const char *supply; | ||
67 | const char *regulator; | ||
68 | }; | ||
69 | |||
70 | static inline struct regulator_dev *to_rdev(struct device *d) | ||
71 | { | ||
72 | return container_of(d, struct regulator_dev, dev); | ||
73 | } | ||
74 | |||
75 | /* | ||
76 | * struct regulator | ||
77 | * | ||
78 | * One for each consumer device. | ||
79 | */ | ||
80 | struct regulator { | ||
81 | struct device *dev; | ||
82 | struct list_head list; | ||
83 | int uA_load; | ||
84 | int min_uV; | ||
85 | int max_uV; | ||
86 | int enabled; /* client has called enabled */ | ||
87 | char *supply_name; | ||
88 | struct device_attribute dev_attr; | ||
89 | struct regulator_dev *rdev; | ||
90 | }; | ||
91 | |||
92 | static int _regulator_is_enabled(struct regulator_dev *rdev); | ||
93 | static int _regulator_disable(struct regulator_dev *rdev); | ||
94 | static int _regulator_get_voltage(struct regulator_dev *rdev); | ||
95 | static int _regulator_get_current_limit(struct regulator_dev *rdev); | ||
96 | static unsigned int _regulator_get_mode(struct regulator_dev *rdev); | ||
97 | static void _notifier_call_chain(struct regulator_dev *rdev, | ||
98 | unsigned long event, void *data); | ||
99 | |||
100 | /* gets the regulator for a given consumer device */ | ||
101 | static struct regulator *get_device_regulator(struct device *dev) | ||
102 | { | ||
103 | struct regulator *regulator = NULL; | ||
104 | struct regulator_dev *rdev; | ||
105 | |||
106 | mutex_lock(®ulator_list_mutex); | ||
107 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
108 | mutex_lock(&rdev->mutex); | ||
109 | list_for_each_entry(regulator, &rdev->consumer_list, list) { | ||
110 | if (regulator->dev == dev) { | ||
111 | mutex_unlock(&rdev->mutex); | ||
112 | mutex_unlock(®ulator_list_mutex); | ||
113 | return regulator; | ||
114 | } | ||
115 | } | ||
116 | mutex_unlock(&rdev->mutex); | ||
117 | } | ||
118 | mutex_unlock(®ulator_list_mutex); | ||
119 | return NULL; | ||
120 | } | ||
121 | |||
122 | /* Platform voltage constraint check */ | ||
123 | static int regulator_check_voltage(struct regulator_dev *rdev, | ||
124 | int *min_uV, int *max_uV) | ||
125 | { | ||
126 | BUG_ON(*min_uV > *max_uV); | ||
127 | |||
128 | if (!rdev->constraints) { | ||
129 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | ||
130 | rdev->desc->name); | ||
131 | return -ENODEV; | ||
132 | } | ||
133 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { | ||
134 | printk(KERN_ERR "%s: operation not allowed for %s\n", | ||
135 | __func__, rdev->desc->name); | ||
136 | return -EPERM; | ||
137 | } | ||
138 | |||
139 | if (*max_uV > rdev->constraints->max_uV) | ||
140 | *max_uV = rdev->constraints->max_uV; | ||
141 | if (*min_uV < rdev->constraints->min_uV) | ||
142 | *min_uV = rdev->constraints->min_uV; | ||
143 | |||
144 | if (*min_uV > *max_uV) | ||
145 | return -EINVAL; | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | /* current constraint check */ | ||
151 | static int regulator_check_current_limit(struct regulator_dev *rdev, | ||
152 | int *min_uA, int *max_uA) | ||
153 | { | ||
154 | BUG_ON(*min_uA > *max_uA); | ||
155 | |||
156 | if (!rdev->constraints) { | ||
157 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | ||
158 | rdev->desc->name); | ||
159 | return -ENODEV; | ||
160 | } | ||
161 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { | ||
162 | printk(KERN_ERR "%s: operation not allowed for %s\n", | ||
163 | __func__, rdev->desc->name); | ||
164 | return -EPERM; | ||
165 | } | ||
166 | |||
167 | if (*max_uA > rdev->constraints->max_uA) | ||
168 | *max_uA = rdev->constraints->max_uA; | ||
169 | if (*min_uA < rdev->constraints->min_uA) | ||
170 | *min_uA = rdev->constraints->min_uA; | ||
171 | |||
172 | if (*min_uA > *max_uA) | ||
173 | return -EINVAL; | ||
174 | |||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | /* operating mode constraint check */ | ||
179 | static int regulator_check_mode(struct regulator_dev *rdev, int mode) | ||
180 | { | ||
181 | if (!rdev->constraints) { | ||
182 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | ||
183 | rdev->desc->name); | ||
184 | return -ENODEV; | ||
185 | } | ||
186 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { | ||
187 | printk(KERN_ERR "%s: operation not allowed for %s\n", | ||
188 | __func__, rdev->desc->name); | ||
189 | return -EPERM; | ||
190 | } | ||
191 | if (!(rdev->constraints->valid_modes_mask & mode)) { | ||
192 | printk(KERN_ERR "%s: invalid mode %x for %s\n", | ||
193 | __func__, mode, rdev->desc->name); | ||
194 | return -EINVAL; | ||
195 | } | ||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | /* dynamic regulator mode switching constraint check */ | ||
200 | static int regulator_check_drms(struct regulator_dev *rdev) | ||
201 | { | ||
202 | if (!rdev->constraints) { | ||
203 | printk(KERN_ERR "%s: no constraints for %s\n", __func__, | ||
204 | rdev->desc->name); | ||
205 | return -ENODEV; | ||
206 | } | ||
207 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { | ||
208 | printk(KERN_ERR "%s: operation not allowed for %s\n", | ||
209 | __func__, rdev->desc->name); | ||
210 | return -EPERM; | ||
211 | } | ||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | static ssize_t device_requested_uA_show(struct device *dev, | ||
216 | struct device_attribute *attr, char *buf) | ||
217 | { | ||
218 | struct regulator *regulator; | ||
219 | |||
220 | regulator = get_device_regulator(dev); | ||
221 | if (regulator == NULL) | ||
222 | return 0; | ||
223 | |||
224 | return sprintf(buf, "%d\n", regulator->uA_load); | ||
225 | } | ||
226 | |||
227 | static ssize_t regulator_uV_show(struct device *dev, | ||
228 | struct device_attribute *attr, char *buf) | ||
229 | { | ||
230 | struct regulator_dev *rdev = to_rdev(dev); | ||
231 | ssize_t ret; | ||
232 | |||
233 | mutex_lock(&rdev->mutex); | ||
234 | ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev)); | ||
235 | mutex_unlock(&rdev->mutex); | ||
236 | |||
237 | return ret; | ||
238 | } | ||
239 | |||
240 | static ssize_t regulator_uA_show(struct device *dev, | ||
241 | struct device_attribute *attr, char *buf) | ||
242 | { | ||
243 | struct regulator_dev *rdev = to_rdev(dev); | ||
244 | |||
245 | return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); | ||
246 | } | ||
247 | |||
248 | static ssize_t regulator_opmode_show(struct device *dev, | ||
249 | struct device_attribute *attr, char *buf) | ||
250 | { | ||
251 | struct regulator_dev *rdev = to_rdev(dev); | ||
252 | int mode = _regulator_get_mode(rdev); | ||
253 | |||
254 | switch (mode) { | ||
255 | case REGULATOR_MODE_FAST: | ||
256 | return sprintf(buf, "fast\n"); | ||
257 | case REGULATOR_MODE_NORMAL: | ||
258 | return sprintf(buf, "normal\n"); | ||
259 | case REGULATOR_MODE_IDLE: | ||
260 | return sprintf(buf, "idle\n"); | ||
261 | case REGULATOR_MODE_STANDBY: | ||
262 | return sprintf(buf, "standby\n"); | ||
263 | } | ||
264 | return sprintf(buf, "unknown\n"); | ||
265 | } | ||
266 | |||
267 | static ssize_t regulator_state_show(struct device *dev, | ||
268 | struct device_attribute *attr, char *buf) | ||
269 | { | ||
270 | struct regulator_dev *rdev = to_rdev(dev); | ||
271 | int state = _regulator_is_enabled(rdev); | ||
272 | |||
273 | if (state > 0) | ||
274 | return sprintf(buf, "enabled\n"); | ||
275 | else if (state == 0) | ||
276 | return sprintf(buf, "disabled\n"); | ||
277 | else | ||
278 | return sprintf(buf, "unknown\n"); | ||
279 | } | ||
280 | |||
281 | static ssize_t regulator_min_uA_show(struct device *dev, | ||
282 | struct device_attribute *attr, char *buf) | ||
283 | { | ||
284 | struct regulator_dev *rdev = to_rdev(dev); | ||
285 | |||
286 | if (!rdev->constraints) | ||
287 | return sprintf(buf, "constraint not defined\n"); | ||
288 | |||
289 | return sprintf(buf, "%d\n", rdev->constraints->min_uA); | ||
290 | } | ||
291 | |||
292 | static ssize_t regulator_max_uA_show(struct device *dev, | ||
293 | struct device_attribute *attr, char *buf) | ||
294 | { | ||
295 | struct regulator_dev *rdev = to_rdev(dev); | ||
296 | |||
297 | if (!rdev->constraints) | ||
298 | return sprintf(buf, "constraint not defined\n"); | ||
299 | |||
300 | return sprintf(buf, "%d\n", rdev->constraints->max_uA); | ||
301 | } | ||
302 | |||
303 | static ssize_t regulator_min_uV_show(struct device *dev, | ||
304 | struct device_attribute *attr, char *buf) | ||
305 | { | ||
306 | struct regulator_dev *rdev = to_rdev(dev); | ||
307 | |||
308 | if (!rdev->constraints) | ||
309 | return sprintf(buf, "constraint not defined\n"); | ||
310 | |||
311 | return sprintf(buf, "%d\n", rdev->constraints->min_uV); | ||
312 | } | ||
313 | |||
314 | static ssize_t regulator_max_uV_show(struct device *dev, | ||
315 | struct device_attribute *attr, char *buf) | ||
316 | { | ||
317 | struct regulator_dev *rdev = to_rdev(dev); | ||
318 | |||
319 | if (!rdev->constraints) | ||
320 | return sprintf(buf, "constraint not defined\n"); | ||
321 | |||
322 | return sprintf(buf, "%d\n", rdev->constraints->max_uV); | ||
323 | } | ||
324 | |||
325 | static ssize_t regulator_total_uA_show(struct device *dev, | ||
326 | struct device_attribute *attr, char *buf) | ||
327 | { | ||
328 | struct regulator_dev *rdev = to_rdev(dev); | ||
329 | struct regulator *regulator; | ||
330 | int uA = 0; | ||
331 | |||
332 | mutex_lock(&rdev->mutex); | ||
333 | list_for_each_entry(regulator, &rdev->consumer_list, list) | ||
334 | uA += regulator->uA_load; | ||
335 | mutex_unlock(&rdev->mutex); | ||
336 | return sprintf(buf, "%d\n", uA); | ||
337 | } | ||
338 | |||
339 | static ssize_t regulator_num_users_show(struct device *dev, | ||
340 | struct device_attribute *attr, char *buf) | ||
341 | { | ||
342 | struct regulator_dev *rdev = to_rdev(dev); | ||
343 | return sprintf(buf, "%d\n", rdev->use_count); | ||
344 | } | ||
345 | |||
346 | static ssize_t regulator_type_show(struct device *dev, | ||
347 | struct device_attribute *attr, char *buf) | ||
348 | { | ||
349 | struct regulator_dev *rdev = to_rdev(dev); | ||
350 | |||
351 | switch (rdev->desc->type) { | ||
352 | case REGULATOR_VOLTAGE: | ||
353 | return sprintf(buf, "voltage\n"); | ||
354 | case REGULATOR_CURRENT: | ||
355 | return sprintf(buf, "current\n"); | ||
356 | } | ||
357 | return sprintf(buf, "unknown\n"); | ||
358 | } | ||
359 | |||
360 | static ssize_t regulator_suspend_mem_uV_show(struct device *dev, | ||
361 | struct device_attribute *attr, char *buf) | ||
362 | { | ||
363 | struct regulator_dev *rdev = to_rdev(dev); | ||
364 | |||
365 | if (!rdev->constraints) | ||
366 | return sprintf(buf, "not defined\n"); | ||
367 | return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); | ||
368 | } | ||
369 | |||
370 | static ssize_t regulator_suspend_disk_uV_show(struct device *dev, | ||
371 | struct device_attribute *attr, char *buf) | ||
372 | { | ||
373 | struct regulator_dev *rdev = to_rdev(dev); | ||
374 | |||
375 | if (!rdev->constraints) | ||
376 | return sprintf(buf, "not defined\n"); | ||
377 | return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); | ||
378 | } | ||
379 | |||
380 | static ssize_t regulator_suspend_standby_uV_show(struct device *dev, | ||
381 | struct device_attribute *attr, char *buf) | ||
382 | { | ||
383 | struct regulator_dev *rdev = to_rdev(dev); | ||
384 | |||
385 | if (!rdev->constraints) | ||
386 | return sprintf(buf, "not defined\n"); | ||
387 | return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); | ||
388 | } | ||
389 | |||
390 | static ssize_t suspend_opmode_show(struct regulator_dev *rdev, | ||
391 | unsigned int mode, char *buf) | ||
392 | { | ||
393 | switch (mode) { | ||
394 | case REGULATOR_MODE_FAST: | ||
395 | return sprintf(buf, "fast\n"); | ||
396 | case REGULATOR_MODE_NORMAL: | ||
397 | return sprintf(buf, "normal\n"); | ||
398 | case REGULATOR_MODE_IDLE: | ||
399 | return sprintf(buf, "idle\n"); | ||
400 | case REGULATOR_MODE_STANDBY: | ||
401 | return sprintf(buf, "standby\n"); | ||
402 | } | ||
403 | return sprintf(buf, "unknown\n"); | ||
404 | } | ||
405 | |||
406 | static ssize_t regulator_suspend_mem_mode_show(struct device *dev, | ||
407 | struct device_attribute *attr, char *buf) | ||
408 | { | ||
409 | struct regulator_dev *rdev = to_rdev(dev); | ||
410 | |||
411 | if (!rdev->constraints) | ||
412 | return sprintf(buf, "not defined\n"); | ||
413 | return suspend_opmode_show(rdev, | ||
414 | rdev->constraints->state_mem.mode, buf); | ||
415 | } | ||
416 | |||
417 | static ssize_t regulator_suspend_disk_mode_show(struct device *dev, | ||
418 | struct device_attribute *attr, char *buf) | ||
419 | { | ||
420 | struct regulator_dev *rdev = to_rdev(dev); | ||
421 | |||
422 | if (!rdev->constraints) | ||
423 | return sprintf(buf, "not defined\n"); | ||
424 | return suspend_opmode_show(rdev, | ||
425 | rdev->constraints->state_disk.mode, buf); | ||
426 | } | ||
427 | |||
428 | static ssize_t regulator_suspend_standby_mode_show(struct device *dev, | ||
429 | struct device_attribute *attr, char *buf) | ||
430 | { | ||
431 | struct regulator_dev *rdev = to_rdev(dev); | ||
432 | |||
433 | if (!rdev->constraints) | ||
434 | return sprintf(buf, "not defined\n"); | ||
435 | return suspend_opmode_show(rdev, | ||
436 | rdev->constraints->state_standby.mode, buf); | ||
437 | } | ||
438 | |||
439 | static ssize_t regulator_suspend_mem_state_show(struct device *dev, | ||
440 | struct device_attribute *attr, char *buf) | ||
441 | { | ||
442 | struct regulator_dev *rdev = to_rdev(dev); | ||
443 | |||
444 | if (!rdev->constraints) | ||
445 | return sprintf(buf, "not defined\n"); | ||
446 | |||
447 | if (rdev->constraints->state_mem.enabled) | ||
448 | return sprintf(buf, "enabled\n"); | ||
449 | else | ||
450 | return sprintf(buf, "disabled\n"); | ||
451 | } | ||
452 | |||
453 | static ssize_t regulator_suspend_disk_state_show(struct device *dev, | ||
454 | struct device_attribute *attr, char *buf) | ||
455 | { | ||
456 | struct regulator_dev *rdev = to_rdev(dev); | ||
457 | |||
458 | if (!rdev->constraints) | ||
459 | return sprintf(buf, "not defined\n"); | ||
460 | |||
461 | if (rdev->constraints->state_disk.enabled) | ||
462 | return sprintf(buf, "enabled\n"); | ||
463 | else | ||
464 | return sprintf(buf, "disabled\n"); | ||
465 | } | ||
466 | |||
467 | static ssize_t regulator_suspend_standby_state_show(struct device *dev, | ||
468 | struct device_attribute *attr, char *buf) | ||
469 | { | ||
470 | struct regulator_dev *rdev = to_rdev(dev); | ||
471 | |||
472 | if (!rdev->constraints) | ||
473 | return sprintf(buf, "not defined\n"); | ||
474 | |||
475 | if (rdev->constraints->state_standby.enabled) | ||
476 | return sprintf(buf, "enabled\n"); | ||
477 | else | ||
478 | return sprintf(buf, "disabled\n"); | ||
479 | } | ||
480 | static struct device_attribute regulator_dev_attrs[] = { | ||
481 | __ATTR(microvolts, 0444, regulator_uV_show, NULL), | ||
482 | __ATTR(microamps, 0444, regulator_uA_show, NULL), | ||
483 | __ATTR(opmode, 0444, regulator_opmode_show, NULL), | ||
484 | __ATTR(state, 0444, regulator_state_show, NULL), | ||
485 | __ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL), | ||
486 | __ATTR(min_microamps, 0444, regulator_min_uA_show, NULL), | ||
487 | __ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL), | ||
488 | __ATTR(max_microamps, 0444, regulator_max_uA_show, NULL), | ||
489 | __ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL), | ||
490 | __ATTR(num_users, 0444, regulator_num_users_show, NULL), | ||
491 | __ATTR(type, 0444, regulator_type_show, NULL), | ||
492 | __ATTR(suspend_mem_microvolts, 0444, | ||
493 | regulator_suspend_mem_uV_show, NULL), | ||
494 | __ATTR(suspend_disk_microvolts, 0444, | ||
495 | regulator_suspend_disk_uV_show, NULL), | ||
496 | __ATTR(suspend_standby_microvolts, 0444, | ||
497 | regulator_suspend_standby_uV_show, NULL), | ||
498 | __ATTR(suspend_mem_mode, 0444, | ||
499 | regulator_suspend_mem_mode_show, NULL), | ||
500 | __ATTR(suspend_disk_mode, 0444, | ||
501 | regulator_suspend_disk_mode_show, NULL), | ||
502 | __ATTR(suspend_standby_mode, 0444, | ||
503 | regulator_suspend_standby_mode_show, NULL), | ||
504 | __ATTR(suspend_mem_state, 0444, | ||
505 | regulator_suspend_mem_state_show, NULL), | ||
506 | __ATTR(suspend_disk_state, 0444, | ||
507 | regulator_suspend_disk_state_show, NULL), | ||
508 | __ATTR(suspend_standby_state, 0444, | ||
509 | regulator_suspend_standby_state_show, NULL), | ||
510 | __ATTR_NULL, | ||
511 | }; | ||
512 | |||
513 | static void regulator_dev_release(struct device *dev) | ||
514 | { | ||
515 | struct regulator_dev *rdev = to_rdev(dev); | ||
516 | kfree(rdev); | ||
517 | } | ||
518 | |||
519 | static struct class regulator_class = { | ||
520 | .name = "regulator", | ||
521 | .dev_release = regulator_dev_release, | ||
522 | .dev_attrs = regulator_dev_attrs, | ||
523 | }; | ||
524 | |||
525 | /* Calculate the new optimum regulator operating mode based on the new total | ||
526 | * consumer load. All locks held by caller */ | ||
527 | static void drms_uA_update(struct regulator_dev *rdev) | ||
528 | { | ||
529 | struct regulator *sibling; | ||
530 | int current_uA = 0, output_uV, input_uV, err; | ||
531 | unsigned int mode; | ||
532 | |||
533 | err = regulator_check_drms(rdev); | ||
534 | if (err < 0 || !rdev->desc->ops->get_optimum_mode || | ||
535 | !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode); | ||
536 | return; | ||
537 | |||
538 | /* get output voltage */ | ||
539 | output_uV = rdev->desc->ops->get_voltage(rdev); | ||
540 | if (output_uV <= 0) | ||
541 | return; | ||
542 | |||
543 | /* get input voltage */ | ||
544 | if (rdev->supply && rdev->supply->desc->ops->get_voltage) | ||
545 | input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); | ||
546 | else | ||
547 | input_uV = rdev->constraints->input_uV; | ||
548 | if (input_uV <= 0) | ||
549 | return; | ||
550 | |||
551 | /* calc total requested load */ | ||
552 | list_for_each_entry(sibling, &rdev->consumer_list, list) | ||
553 | current_uA += sibling->uA_load; | ||
554 | |||
555 | /* now get the optimum mode for our new total regulator load */ | ||
556 | mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, | ||
557 | output_uV, current_uA); | ||
558 | |||
559 | /* check the new mode is allowed */ | ||
560 | err = regulator_check_mode(rdev, mode); | ||
561 | if (err == 0) | ||
562 | rdev->desc->ops->set_mode(rdev, mode); | ||
563 | } | ||
564 | |||
565 | static int suspend_set_state(struct regulator_dev *rdev, | ||
566 | struct regulator_state *rstate) | ||
567 | { | ||
568 | int ret = 0; | ||
569 | |||
570 | /* enable & disable are mandatory for suspend control */ | ||
571 | if (!rdev->desc->ops->set_suspend_enable || | ||
572 | !rdev->desc->ops->set_suspend_disable) | ||
573 | return -EINVAL; | ||
574 | |||
575 | if (rstate->enabled) | ||
576 | ret = rdev->desc->ops->set_suspend_enable(rdev); | ||
577 | else | ||
578 | ret = rdev->desc->ops->set_suspend_disable(rdev); | ||
579 | if (ret < 0) { | ||
580 | printk(KERN_ERR "%s: failed to enabled/disable\n", __func__); | ||
581 | return ret; | ||
582 | } | ||
583 | |||
584 | if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { | ||
585 | ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); | ||
586 | if (ret < 0) { | ||
587 | printk(KERN_ERR "%s: failed to set voltage\n", | ||
588 | __func__); | ||
589 | return ret; | ||
590 | } | ||
591 | } | ||
592 | |||
593 | if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { | ||
594 | ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); | ||
595 | if (ret < 0) { | ||
596 | printk(KERN_ERR "%s: failed to set mode\n", __func__); | ||
597 | return ret; | ||
598 | } | ||
599 | } | ||
600 | return ret; | ||
601 | } | ||
602 | |||
603 | /* locks held by caller */ | ||
604 | static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) | ||
605 | { | ||
606 | if (!rdev->constraints) | ||
607 | return -EINVAL; | ||
608 | |||
609 | switch (state) { | ||
610 | case PM_SUSPEND_STANDBY: | ||
611 | return suspend_set_state(rdev, | ||
612 | &rdev->constraints->state_standby); | ||
613 | case PM_SUSPEND_MEM: | ||
614 | return suspend_set_state(rdev, | ||
615 | &rdev->constraints->state_mem); | ||
616 | case PM_SUSPEND_MAX: | ||
617 | return suspend_set_state(rdev, | ||
618 | &rdev->constraints->state_disk); | ||
619 | default: | ||
620 | return -EINVAL; | ||
621 | } | ||
622 | } | ||
623 | |||
624 | static void print_constraints(struct regulator_dev *rdev) | ||
625 | { | ||
626 | struct regulation_constraints *constraints = rdev->constraints; | ||
627 | char buf[80]; | ||
628 | int count; | ||
629 | |||
630 | if (rdev->desc->type == REGULATOR_VOLTAGE) { | ||
631 | if (constraints->min_uV == constraints->max_uV) | ||
632 | count = sprintf(buf, "%d mV ", | ||
633 | constraints->min_uV / 1000); | ||
634 | else | ||
635 | count = sprintf(buf, "%d <--> %d mV ", | ||
636 | constraints->min_uV / 1000, | ||
637 | constraints->max_uV / 1000); | ||
638 | } else { | ||
639 | if (constraints->min_uA == constraints->max_uA) | ||
640 | count = sprintf(buf, "%d mA ", | ||
641 | constraints->min_uA / 1000); | ||
642 | else | ||
643 | count = sprintf(buf, "%d <--> %d mA ", | ||
644 | constraints->min_uA / 1000, | ||
645 | constraints->max_uA / 1000); | ||
646 | } | ||
647 | if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) | ||
648 | count += sprintf(buf + count, "fast "); | ||
649 | if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) | ||
650 | count += sprintf(buf + count, "normal "); | ||
651 | if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE) | ||
652 | count += sprintf(buf + count, "idle "); | ||
653 | if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) | ||
654 | count += sprintf(buf + count, "standby"); | ||
655 | |||
656 | printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); | ||
657 | } | ||
658 | |||
659 | #define REG_STR_SIZE 32 | ||
660 | |||
661 | static struct regulator *create_regulator(struct regulator_dev *rdev, | ||
662 | struct device *dev, | ||
663 | const char *supply_name) | ||
664 | { | ||
665 | struct regulator *regulator; | ||
666 | char buf[REG_STR_SIZE]; | ||
667 | int err, size; | ||
668 | |||
669 | regulator = kzalloc(sizeof(*regulator), GFP_KERNEL); | ||
670 | if (regulator == NULL) | ||
671 | return NULL; | ||
672 | |||
673 | mutex_lock(&rdev->mutex); | ||
674 | regulator->rdev = rdev; | ||
675 | list_add(®ulator->list, &rdev->consumer_list); | ||
676 | |||
677 | if (dev) { | ||
678 | /* create a 'requested_microamps_name' sysfs entry */ | ||
679 | size = scnprintf(buf, REG_STR_SIZE, "microamps_requested_%s", | ||
680 | supply_name); | ||
681 | if (size >= REG_STR_SIZE) | ||
682 | goto overflow_err; | ||
683 | |||
684 | regulator->dev = dev; | ||
685 | regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL); | ||
686 | if (regulator->dev_attr.attr.name == NULL) | ||
687 | goto attr_name_err; | ||
688 | |||
689 | regulator->dev_attr.attr.owner = THIS_MODULE; | ||
690 | regulator->dev_attr.attr.mode = 0444; | ||
691 | regulator->dev_attr.show = device_requested_uA_show; | ||
692 | err = device_create_file(dev, ®ulator->dev_attr); | ||
693 | if (err < 0) { | ||
694 | printk(KERN_WARNING "%s: could not add regulator_dev" | ||
695 | " load sysfs\n", __func__); | ||
696 | goto attr_name_err; | ||
697 | } | ||
698 | |||
699 | /* also add a link to the device sysfs entry */ | ||
700 | size = scnprintf(buf, REG_STR_SIZE, "%s-%s", | ||
701 | dev->kobj.name, supply_name); | ||
702 | if (size >= REG_STR_SIZE) | ||
703 | goto attr_err; | ||
704 | |||
705 | regulator->supply_name = kstrdup(buf, GFP_KERNEL); | ||
706 | if (regulator->supply_name == NULL) | ||
707 | goto attr_err; | ||
708 | |||
709 | err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, | ||
710 | buf); | ||
711 | if (err) { | ||
712 | printk(KERN_WARNING | ||
713 | "%s: could not add device link %s err %d\n", | ||
714 | __func__, dev->kobj.name, err); | ||
715 | device_remove_file(dev, ®ulator->dev_attr); | ||
716 | goto link_name_err; | ||
717 | } | ||
718 | } | ||
719 | mutex_unlock(&rdev->mutex); | ||
720 | return regulator; | ||
721 | link_name_err: | ||
722 | kfree(regulator->supply_name); | ||
723 | attr_err: | ||
724 | device_remove_file(regulator->dev, ®ulator->dev_attr); | ||
725 | attr_name_err: | ||
726 | kfree(regulator->dev_attr.attr.name); | ||
727 | overflow_err: | ||
728 | list_del(®ulator->list); | ||
729 | kfree(regulator); | ||
730 | mutex_unlock(&rdev->mutex); | ||
731 | return NULL; | ||
732 | } | ||
733 | |||
734 | /** | ||
735 | * regulator_get - lookup and obtain a reference to a regulator. | ||
736 | * @dev: device for regulator "consumer" | ||
737 | * @id: Supply name or regulator ID. | ||
738 | * | ||
739 | * Returns a struct regulator corresponding to the regulator producer, | ||
740 | * or IS_ERR() condition containing errno. Use of supply names | ||
741 | * configured via regulator_set_device_supply() is strongly | ||
742 | * encouraged. | ||
743 | */ | ||
744 | struct regulator *regulator_get(struct device *dev, const char *id) | ||
745 | { | ||
746 | struct regulator_dev *rdev; | ||
747 | struct regulator_map *map; | ||
748 | struct regulator *regulator = ERR_PTR(-ENODEV); | ||
749 | const char *supply = id; | ||
750 | |||
751 | if (id == NULL) { | ||
752 | printk(KERN_ERR "regulator: get() with no identifier\n"); | ||
753 | return regulator; | ||
754 | } | ||
755 | |||
756 | mutex_lock(®ulator_list_mutex); | ||
757 | |||
758 | list_for_each_entry(map, ®ulator_map_list, list) { | ||
759 | if (dev == map->dev && | ||
760 | strcmp(map->supply, id) == 0) { | ||
761 | supply = map->regulator; | ||
762 | break; | ||
763 | } | ||
764 | } | ||
765 | |||
766 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
767 | if (strcmp(supply, rdev->desc->name) == 0 && | ||
768 | try_module_get(rdev->owner)) | ||
769 | goto found; | ||
770 | } | ||
771 | printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", | ||
772 | id); | ||
773 | mutex_unlock(®ulator_list_mutex); | ||
774 | return regulator; | ||
775 | |||
776 | found: | ||
777 | regulator = create_regulator(rdev, dev, id); | ||
778 | if (regulator == NULL) { | ||
779 | regulator = ERR_PTR(-ENOMEM); | ||
780 | module_put(rdev->owner); | ||
781 | } | ||
782 | |||
783 | mutex_unlock(®ulator_list_mutex); | ||
784 | return regulator; | ||
785 | } | ||
786 | EXPORT_SYMBOL_GPL(regulator_get); | ||
787 | |||
788 | /** | ||
789 | * regulator_put - "free" the regulator source | ||
790 | * @regulator: regulator source | ||
791 | * | ||
792 | * Note: drivers must ensure that all regulator_enable calls made on this | ||
793 | * regulator source are balanced by regulator_disable calls prior to calling | ||
794 | * this function. | ||
795 | */ | ||
796 | void regulator_put(struct regulator *regulator) | ||
797 | { | ||
798 | struct regulator_dev *rdev; | ||
799 | |||
800 | if (regulator == NULL || IS_ERR(regulator)) | ||
801 | return; | ||
802 | |||
803 | if (regulator->enabled) { | ||
804 | printk(KERN_WARNING "Releasing supply %s while enabled\n", | ||
805 | regulator->supply_name); | ||
806 | WARN_ON(regulator->enabled); | ||
807 | regulator_disable(regulator); | ||
808 | } | ||
809 | |||
810 | mutex_lock(®ulator_list_mutex); | ||
811 | rdev = regulator->rdev; | ||
812 | |||
813 | /* remove any sysfs entries */ | ||
814 | if (regulator->dev) { | ||
815 | sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); | ||
816 | kfree(regulator->supply_name); | ||
817 | device_remove_file(regulator->dev, ®ulator->dev_attr); | ||
818 | kfree(regulator->dev_attr.attr.name); | ||
819 | } | ||
820 | list_del(®ulator->list); | ||
821 | kfree(regulator); | ||
822 | |||
823 | module_put(rdev->owner); | ||
824 | mutex_unlock(®ulator_list_mutex); | ||
825 | } | ||
826 | EXPORT_SYMBOL_GPL(regulator_put); | ||
827 | |||
828 | /* locks held by regulator_enable() */ | ||
829 | static int _regulator_enable(struct regulator_dev *rdev) | ||
830 | { | ||
831 | int ret = -EINVAL; | ||
832 | |||
833 | if (!rdev->constraints) { | ||
834 | printk(KERN_ERR "%s: %s has no constraints\n", | ||
835 | __func__, rdev->desc->name); | ||
836 | return ret; | ||
837 | } | ||
838 | |||
839 | /* do we need to enable the supply regulator first */ | ||
840 | if (rdev->supply) { | ||
841 | ret = _regulator_enable(rdev->supply); | ||
842 | if (ret < 0) { | ||
843 | printk(KERN_ERR "%s: failed to enable %s: %d\n", | ||
844 | __func__, rdev->desc->name, ret); | ||
845 | return ret; | ||
846 | } | ||
847 | } | ||
848 | |||
849 | /* check voltage and requested load before enabling */ | ||
850 | if (rdev->desc->ops->enable) { | ||
851 | |||
852 | if (rdev->constraints && | ||
853 | (rdev->constraints->valid_ops_mask & | ||
854 | REGULATOR_CHANGE_DRMS)) | ||
855 | drms_uA_update(rdev); | ||
856 | |||
857 | ret = rdev->desc->ops->enable(rdev); | ||
858 | if (ret < 0) { | ||
859 | printk(KERN_ERR "%s: failed to enable %s: %d\n", | ||
860 | __func__, rdev->desc->name, ret); | ||
861 | return ret; | ||
862 | } | ||
863 | rdev->use_count++; | ||
864 | return ret; | ||
865 | } | ||
866 | |||
867 | return ret; | ||
868 | } | ||
869 | |||
870 | /** | ||
871 | * regulator_enable - enable regulator output | ||
872 | * @regulator: regulator source | ||
873 | * | ||
874 | * Enable the regulator output at the predefined voltage or current value. | ||
875 | * NOTE: the output value can be set by other drivers, boot loader or may be | ||
876 | * hardwired in the regulator. | ||
877 | * NOTE: calls to regulator_enable() must be balanced with calls to | ||
878 | * regulator_disable(). | ||
879 | */ | ||
880 | int regulator_enable(struct regulator *regulator) | ||
881 | { | ||
882 | int ret; | ||
883 | |||
884 | if (regulator->enabled) { | ||
885 | printk(KERN_CRIT "Regulator %s already enabled\n", | ||
886 | regulator->supply_name); | ||
887 | WARN_ON(regulator->enabled); | ||
888 | return 0; | ||
889 | } | ||
890 | |||
891 | mutex_lock(®ulator->rdev->mutex); | ||
892 | regulator->enabled = 1; | ||
893 | ret = _regulator_enable(regulator->rdev); | ||
894 | if (ret != 0) | ||
895 | regulator->enabled = 0; | ||
896 | mutex_unlock(®ulator->rdev->mutex); | ||
897 | return ret; | ||
898 | } | ||
899 | EXPORT_SYMBOL_GPL(regulator_enable); | ||
900 | |||
901 | /* locks held by regulator_disable() */ | ||
902 | static int _regulator_disable(struct regulator_dev *rdev) | ||
903 | { | ||
904 | int ret = 0; | ||
905 | |||
906 | /* are we the last user and permitted to disable ? */ | ||
907 | if (rdev->use_count == 1 && !rdev->constraints->always_on) { | ||
908 | |||
909 | /* we are last user */ | ||
910 | if (rdev->desc->ops->disable) { | ||
911 | ret = rdev->desc->ops->disable(rdev); | ||
912 | if (ret < 0) { | ||
913 | printk(KERN_ERR "%s: failed to disable %s\n", | ||
914 | __func__, rdev->desc->name); | ||
915 | return ret; | ||
916 | } | ||
917 | } | ||
918 | |||
919 | /* decrease our supplies ref count and disable if required */ | ||
920 | if (rdev->supply) | ||
921 | _regulator_disable(rdev->supply); | ||
922 | |||
923 | rdev->use_count = 0; | ||
924 | } else if (rdev->use_count > 1) { | ||
925 | |||
926 | if (rdev->constraints && | ||
927 | (rdev->constraints->valid_ops_mask & | ||
928 | REGULATOR_CHANGE_DRMS)) | ||
929 | drms_uA_update(rdev); | ||
930 | |||
931 | rdev->use_count--; | ||
932 | } | ||
933 | return ret; | ||
934 | } | ||
935 | |||
936 | /** | ||
937 | * regulator_disable - disable regulator output | ||
938 | * @regulator: regulator source | ||
939 | * | ||
940 | * Disable the regulator output voltage or current. | ||
941 | * NOTE: this will only disable the regulator output if no other consumer | ||
942 | * devices have it enabled. | ||
943 | * NOTE: calls to regulator_enable() must be balanced with calls to | ||
944 | * regulator_disable(). | ||
945 | */ | ||
946 | int regulator_disable(struct regulator *regulator) | ||
947 | { | ||
948 | int ret; | ||
949 | |||
950 | if (!regulator->enabled) { | ||
951 | printk(KERN_ERR "%s: not in use by this consumer\n", | ||
952 | __func__); | ||
953 | return 0; | ||
954 | } | ||
955 | |||
956 | mutex_lock(®ulator->rdev->mutex); | ||
957 | regulator->enabled = 0; | ||
958 | regulator->uA_load = 0; | ||
959 | ret = _regulator_disable(regulator->rdev); | ||
960 | mutex_unlock(®ulator->rdev->mutex); | ||
961 | return ret; | ||
962 | } | ||
963 | EXPORT_SYMBOL_GPL(regulator_disable); | ||
964 | |||
965 | /* locks held by regulator_force_disable() */ | ||
966 | static int _regulator_force_disable(struct regulator_dev *rdev) | ||
967 | { | ||
968 | int ret = 0; | ||
969 | |||
970 | /* force disable */ | ||
971 | if (rdev->desc->ops->disable) { | ||
972 | /* ah well, who wants to live forever... */ | ||
973 | ret = rdev->desc->ops->disable(rdev); | ||
974 | if (ret < 0) { | ||
975 | printk(KERN_ERR "%s: failed to force disable %s\n", | ||
976 | __func__, rdev->desc->name); | ||
977 | return ret; | ||
978 | } | ||
979 | /* notify other consumers that power has been forced off */ | ||
980 | _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE, | ||
981 | NULL); | ||
982 | } | ||
983 | |||
984 | /* decrease our supplies ref count and disable if required */ | ||
985 | if (rdev->supply) | ||
986 | _regulator_disable(rdev->supply); | ||
987 | |||
988 | rdev->use_count = 0; | ||
989 | return ret; | ||
990 | } | ||
991 | |||
992 | /** | ||
993 | * regulator_force_disable - force disable regulator output | ||
994 | * @regulator: regulator source | ||
995 | * | ||
996 | * Forcibly disable the regulator output voltage or current. | ||
997 | * NOTE: this *will* disable the regulator output even if other consumer | ||
998 | * devices have it enabled. This should be used for situations when device | ||
999 | * damage will likely occur if the regulator is not disabled (e.g. over temp). | ||
1000 | */ | ||
1001 | int regulator_force_disable(struct regulator *regulator) | ||
1002 | { | ||
1003 | int ret; | ||
1004 | |||
1005 | mutex_lock(®ulator->rdev->mutex); | ||
1006 | regulator->enabled = 0; | ||
1007 | regulator->uA_load = 0; | ||
1008 | ret = _regulator_force_disable(regulator->rdev); | ||
1009 | mutex_unlock(®ulator->rdev->mutex); | ||
1010 | return ret; | ||
1011 | } | ||
1012 | EXPORT_SYMBOL_GPL(regulator_force_disable); | ||
1013 | |||
1014 | static int _regulator_is_enabled(struct regulator_dev *rdev) | ||
1015 | { | ||
1016 | int ret; | ||
1017 | |||
1018 | mutex_lock(&rdev->mutex); | ||
1019 | |||
1020 | /* sanity check */ | ||
1021 | if (!rdev->desc->ops->is_enabled) { | ||
1022 | ret = -EINVAL; | ||
1023 | goto out; | ||
1024 | } | ||
1025 | |||
1026 | ret = rdev->desc->ops->is_enabled(rdev); | ||
1027 | out: | ||
1028 | mutex_unlock(&rdev->mutex); | ||
1029 | return ret; | ||
1030 | } | ||
1031 | |||
1032 | /** | ||
1033 | * regulator_is_enabled - is the regulator output enabled | ||
1034 | * @regulator: regulator source | ||
1035 | * | ||
1036 | * Returns zero for disabled otherwise return number of enable requests. | ||
1037 | */ | ||
1038 | int regulator_is_enabled(struct regulator *regulator) | ||
1039 | { | ||
1040 | return _regulator_is_enabled(regulator->rdev); | ||
1041 | } | ||
1042 | EXPORT_SYMBOL_GPL(regulator_is_enabled); | ||
1043 | |||
1044 | /** | ||
1045 | * regulator_set_voltage - set regulator output voltage | ||
1046 | * @regulator: regulator source | ||
1047 | * @min_uV: Minimum required voltage in uV | ||
1048 | * @max_uV: Maximum acceptable voltage in uV | ||
1049 | * | ||
1050 | * Sets a voltage regulator to the desired output voltage. This can be set | ||
1051 | * during any regulator state. IOW, regulator can be disabled or enabled. | ||
1052 | * | ||
1053 | * If the regulator is enabled then the voltage will change to the new value | ||
1054 | * immediately otherwise if the regulator is disabled the regulator will | ||
1055 | * output at the new voltage when enabled. | ||
1056 | * | ||
1057 | * NOTE: If the regulator is shared between several devices then the lowest | ||
1058 | * request voltage that meets the system constraints will be used. | ||
1059 | * NOTE: Regulator system constraints must be set for this regulator before | ||
1060 | * calling this function otherwise this call will fail. | ||
1061 | */ | ||
1062 | int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) | ||
1063 | { | ||
1064 | struct regulator_dev *rdev = regulator->rdev; | ||
1065 | int ret; | ||
1066 | |||
1067 | mutex_lock(&rdev->mutex); | ||
1068 | |||
1069 | /* sanity check */ | ||
1070 | if (!rdev->desc->ops->set_voltage) { | ||
1071 | ret = -EINVAL; | ||
1072 | goto out; | ||
1073 | } | ||
1074 | |||
1075 | /* constraints check */ | ||
1076 | ret = regulator_check_voltage(rdev, &min_uV, &max_uV); | ||
1077 | if (ret < 0) | ||
1078 | goto out; | ||
1079 | regulator->min_uV = min_uV; | ||
1080 | regulator->max_uV = max_uV; | ||
1081 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); | ||
1082 | |||
1083 | out: | ||
1084 | mutex_unlock(&rdev->mutex); | ||
1085 | return ret; | ||
1086 | } | ||
1087 | EXPORT_SYMBOL_GPL(regulator_set_voltage); | ||
1088 | |||
1089 | static int _regulator_get_voltage(struct regulator_dev *rdev) | ||
1090 | { | ||
1091 | /* sanity check */ | ||
1092 | if (rdev->desc->ops->get_voltage) | ||
1093 | return rdev->desc->ops->get_voltage(rdev); | ||
1094 | else | ||
1095 | return -EINVAL; | ||
1096 | } | ||
1097 | |||
1098 | /** | ||
1099 | * regulator_get_voltage - get regulator output voltage | ||
1100 | * @regulator: regulator source | ||
1101 | * | ||
1102 | * This returns the current regulator voltage in uV. | ||
1103 | * | ||
1104 | * NOTE: If the regulator is disabled it will return the voltage value. This | ||
1105 | * function should not be used to determine regulator state. | ||
1106 | */ | ||
1107 | int regulator_get_voltage(struct regulator *regulator) | ||
1108 | { | ||
1109 | int ret; | ||
1110 | |||
1111 | mutex_lock(®ulator->rdev->mutex); | ||
1112 | |||
1113 | ret = _regulator_get_voltage(regulator->rdev); | ||
1114 | |||
1115 | mutex_unlock(®ulator->rdev->mutex); | ||
1116 | |||
1117 | return ret; | ||
1118 | } | ||
1119 | EXPORT_SYMBOL_GPL(regulator_get_voltage); | ||
1120 | |||
1121 | /** | ||
1122 | * regulator_set_current_limit - set regulator output current limit | ||
1123 | * @regulator: regulator source | ||
1124 | * @min_uA: Minimuum supported current in uA | ||
1125 | * @max_uA: Maximum supported current in uA | ||
1126 | * | ||
1127 | * Sets current sink to the desired output current. This can be set during | ||
1128 | * any regulator state. IOW, regulator can be disabled or enabled. | ||
1129 | * | ||
1130 | * If the regulator is enabled then the current will change to the new value | ||
1131 | * immediately otherwise if the regulator is disabled the regulator will | ||
1132 | * output at the new current when enabled. | ||
1133 | * | ||
1134 | * NOTE: Regulator system constraints must be set for this regulator before | ||
1135 | * calling this function otherwise this call will fail. | ||
1136 | */ | ||
1137 | int regulator_set_current_limit(struct regulator *regulator, | ||
1138 | int min_uA, int max_uA) | ||
1139 | { | ||
1140 | struct regulator_dev *rdev = regulator->rdev; | ||
1141 | int ret; | ||
1142 | |||
1143 | mutex_lock(&rdev->mutex); | ||
1144 | |||
1145 | /* sanity check */ | ||
1146 | if (!rdev->desc->ops->set_current_limit) { | ||
1147 | ret = -EINVAL; | ||
1148 | goto out; | ||
1149 | } | ||
1150 | |||
1151 | /* constraints check */ | ||
1152 | ret = regulator_check_current_limit(rdev, &min_uA, &max_uA); | ||
1153 | if (ret < 0) | ||
1154 | goto out; | ||
1155 | |||
1156 | ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); | ||
1157 | out: | ||
1158 | mutex_unlock(&rdev->mutex); | ||
1159 | return ret; | ||
1160 | } | ||
1161 | EXPORT_SYMBOL_GPL(regulator_set_current_limit); | ||
1162 | |||
1163 | static int _regulator_get_current_limit(struct regulator_dev *rdev) | ||
1164 | { | ||
1165 | int ret; | ||
1166 | |||
1167 | mutex_lock(&rdev->mutex); | ||
1168 | |||
1169 | /* sanity check */ | ||
1170 | if (!rdev->desc->ops->get_current_limit) { | ||
1171 | ret = -EINVAL; | ||
1172 | goto out; | ||
1173 | } | ||
1174 | |||
1175 | ret = rdev->desc->ops->get_current_limit(rdev); | ||
1176 | out: | ||
1177 | mutex_unlock(&rdev->mutex); | ||
1178 | return ret; | ||
1179 | } | ||
1180 | |||
1181 | /** | ||
1182 | * regulator_get_current_limit - get regulator output current | ||
1183 | * @regulator: regulator source | ||
1184 | * | ||
1185 | * This returns the current supplied by the specified current sink in uA. | ||
1186 | * | ||
1187 | * NOTE: If the regulator is disabled it will return the current value. This | ||
1188 | * function should not be used to determine regulator state. | ||
1189 | */ | ||
1190 | int regulator_get_current_limit(struct regulator *regulator) | ||
1191 | { | ||
1192 | return _regulator_get_current_limit(regulator->rdev); | ||
1193 | } | ||
1194 | EXPORT_SYMBOL_GPL(regulator_get_current_limit); | ||
1195 | |||
1196 | /** | ||
1197 | * regulator_set_mode - set regulator operating mode | ||
1198 | * @regulator: regulator source | ||
1199 | * @mode: operating mode - one of the REGULATOR_MODE constants | ||
1200 | * | ||
1201 | * Set regulator operating mode to increase regulator efficiency or improve | ||
1202 | * regulation performance. | ||
1203 | * | ||
1204 | * NOTE: Regulator system constraints must be set for this regulator before | ||
1205 | * calling this function otherwise this call will fail. | ||
1206 | */ | ||
1207 | int regulator_set_mode(struct regulator *regulator, unsigned int mode) | ||
1208 | { | ||
1209 | struct regulator_dev *rdev = regulator->rdev; | ||
1210 | int ret; | ||
1211 | |||
1212 | mutex_lock(&rdev->mutex); | ||
1213 | |||
1214 | /* sanity check */ | ||
1215 | if (!rdev->desc->ops->set_mode) { | ||
1216 | ret = -EINVAL; | ||
1217 | goto out; | ||
1218 | } | ||
1219 | |||
1220 | /* constraints check */ | ||
1221 | ret = regulator_check_mode(rdev, mode); | ||
1222 | if (ret < 0) | ||
1223 | goto out; | ||
1224 | |||
1225 | ret = rdev->desc->ops->set_mode(rdev, mode); | ||
1226 | out: | ||
1227 | mutex_unlock(&rdev->mutex); | ||
1228 | return ret; | ||
1229 | } | ||
1230 | EXPORT_SYMBOL_GPL(regulator_set_mode); | ||
1231 | |||
1232 | static unsigned int _regulator_get_mode(struct regulator_dev *rdev) | ||
1233 | { | ||
1234 | int ret; | ||
1235 | |||
1236 | mutex_lock(&rdev->mutex); | ||
1237 | |||
1238 | /* sanity check */ | ||
1239 | if (!rdev->desc->ops->get_mode) { | ||
1240 | ret = -EINVAL; | ||
1241 | goto out; | ||
1242 | } | ||
1243 | |||
1244 | ret = rdev->desc->ops->get_mode(rdev); | ||
1245 | out: | ||
1246 | mutex_unlock(&rdev->mutex); | ||
1247 | return ret; | ||
1248 | } | ||
1249 | |||
1250 | /** | ||
1251 | * regulator_get_mode - get regulator operating mode | ||
1252 | * @regulator: regulator source | ||
1253 | * | ||
1254 | * Get the current regulator operating mode. | ||
1255 | */ | ||
1256 | unsigned int regulator_get_mode(struct regulator *regulator) | ||
1257 | { | ||
1258 | return _regulator_get_mode(regulator->rdev); | ||
1259 | } | ||
1260 | EXPORT_SYMBOL_GPL(regulator_get_mode); | ||
1261 | |||
1262 | /** | ||
1263 | * regulator_set_optimum_mode - set regulator optimum operating mode | ||
1264 | * @regulator: regulator source | ||
1265 | * @uA_load: load current | ||
1266 | * | ||
1267 | * Notifies the regulator core of a new device load. This is then used by | ||
1268 | * DRMS (if enabled by constraints) to set the most efficient regulator | ||
1269 | * operating mode for the new regulator loading. | ||
1270 | * | ||
1271 | * Consumer devices notify their supply regulator of the maximum power | ||
1272 | * they will require (can be taken from device datasheet in the power | ||
1273 | * consumption tables) when they change operational status and hence power | ||
1274 | * state. Examples of operational state changes that can affect power | ||
1275 | * consumption are :- | ||
1276 | * | ||
1277 | * o Device is opened / closed. | ||
1278 | * o Device I/O is about to begin or has just finished. | ||
1279 | * o Device is idling in between work. | ||
1280 | * | ||
1281 | * This information is also exported via sysfs to userspace. | ||
1282 | * | ||
1283 | * DRMS will sum the total requested load on the regulator and change | ||
1284 | * to the most efficient operating mode if platform constraints allow. | ||
1285 | * | ||
1286 | * Returns the new regulator mode or error. | ||
1287 | */ | ||
1288 | int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | ||
1289 | { | ||
1290 | struct regulator_dev *rdev = regulator->rdev; | ||
1291 | struct regulator *consumer; | ||
1292 | int ret, output_uV, input_uV, total_uA_load = 0; | ||
1293 | unsigned int mode; | ||
1294 | |||
1295 | mutex_lock(&rdev->mutex); | ||
1296 | |||
1297 | regulator->uA_load = uA_load; | ||
1298 | ret = regulator_check_drms(rdev); | ||
1299 | if (ret < 0) | ||
1300 | goto out; | ||
1301 | ret = -EINVAL; | ||
1302 | |||
1303 | /* sanity check */ | ||
1304 | if (!rdev->desc->ops->get_optimum_mode) | ||
1305 | goto out; | ||
1306 | |||
1307 | /* get output voltage */ | ||
1308 | output_uV = rdev->desc->ops->get_voltage(rdev); | ||
1309 | if (output_uV <= 0) { | ||
1310 | printk(KERN_ERR "%s: invalid output voltage found for %s\n", | ||
1311 | __func__, rdev->desc->name); | ||
1312 | goto out; | ||
1313 | } | ||
1314 | |||
1315 | /* get input voltage */ | ||
1316 | if (rdev->supply && rdev->supply->desc->ops->get_voltage) | ||
1317 | input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); | ||
1318 | else | ||
1319 | input_uV = rdev->constraints->input_uV; | ||
1320 | if (input_uV <= 0) { | ||
1321 | printk(KERN_ERR "%s: invalid input voltage found for %s\n", | ||
1322 | __func__, rdev->desc->name); | ||
1323 | goto out; | ||
1324 | } | ||
1325 | |||
1326 | /* calc total requested load for this regulator */ | ||
1327 | list_for_each_entry(consumer, &rdev->consumer_list, list) | ||
1328 | total_uA_load += consumer->uA_load; | ||
1329 | |||
1330 | mode = rdev->desc->ops->get_optimum_mode(rdev, | ||
1331 | input_uV, output_uV, | ||
1332 | total_uA_load); | ||
1333 | if (ret <= 0) { | ||
1334 | printk(KERN_ERR "%s: failed to get optimum mode for %s @" | ||
1335 | " %d uA %d -> %d uV\n", __func__, rdev->desc->name, | ||
1336 | total_uA_load, input_uV, output_uV); | ||
1337 | goto out; | ||
1338 | } | ||
1339 | |||
1340 | ret = rdev->desc->ops->set_mode(rdev, mode); | ||
1341 | if (ret <= 0) { | ||
1342 | printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", | ||
1343 | __func__, mode, rdev->desc->name); | ||
1344 | goto out; | ||
1345 | } | ||
1346 | ret = mode; | ||
1347 | out: | ||
1348 | mutex_unlock(&rdev->mutex); | ||
1349 | return ret; | ||
1350 | } | ||
1351 | EXPORT_SYMBOL_GPL(regulator_set_optimum_mode); | ||
1352 | |||
1353 | /** | ||
1354 | * regulator_register_notifier - register regulator event notifier | ||
1355 | * @regulator: regulator source | ||
1356 | * @notifier_block: notifier block | ||
1357 | * | ||
1358 | * Register notifier block to receive regulator events. | ||
1359 | */ | ||
1360 | int regulator_register_notifier(struct regulator *regulator, | ||
1361 | struct notifier_block *nb) | ||
1362 | { | ||
1363 | return blocking_notifier_chain_register(®ulator->rdev->notifier, | ||
1364 | nb); | ||
1365 | } | ||
1366 | EXPORT_SYMBOL_GPL(regulator_register_notifier); | ||
1367 | |||
1368 | /** | ||
1369 | * regulator_unregister_notifier - unregister regulator event notifier | ||
1370 | * @regulator: regulator source | ||
1371 | * @notifier_block: notifier block | ||
1372 | * | ||
1373 | * Unregister regulator event notifier block. | ||
1374 | */ | ||
1375 | int regulator_unregister_notifier(struct regulator *regulator, | ||
1376 | struct notifier_block *nb) | ||
1377 | { | ||
1378 | return blocking_notifier_chain_unregister(®ulator->rdev->notifier, | ||
1379 | nb); | ||
1380 | } | ||
1381 | EXPORT_SYMBOL_GPL(regulator_unregister_notifier); | ||
1382 | |||
1383 | /* notify regulator consumers and downstream regulator consumers */ | ||
1384 | static void _notifier_call_chain(struct regulator_dev *rdev, | ||
1385 | unsigned long event, void *data) | ||
1386 | { | ||
1387 | struct regulator_dev *_rdev; | ||
1388 | |||
1389 | /* call rdev chain first */ | ||
1390 | mutex_lock(&rdev->mutex); | ||
1391 | blocking_notifier_call_chain(&rdev->notifier, event, NULL); | ||
1392 | mutex_unlock(&rdev->mutex); | ||
1393 | |||
1394 | /* now notify regulator we supply */ | ||
1395 | list_for_each_entry(_rdev, &rdev->supply_list, slist) | ||
1396 | _notifier_call_chain(_rdev, event, data); | ||
1397 | } | ||
1398 | |||
1399 | /** | ||
1400 | * regulator_bulk_get - get multiple regulator consumers | ||
1401 | * | ||
1402 | * @dev: Device to supply | ||
1403 | * @num_consumers: Number of consumers to register | ||
1404 | * @consumers: Configuration of consumers; clients are stored here. | ||
1405 | * | ||
1406 | * @return 0 on success, an errno on failure. | ||
1407 | * | ||
1408 | * This helper function allows drivers to get several regulator | ||
1409 | * consumers in one operation. If any of the regulators cannot be | ||
1410 | * acquired then any regulators that were allocated will be freed | ||
1411 | * before returning to the caller. | ||
1412 | */ | ||
1413 | int regulator_bulk_get(struct device *dev, int num_consumers, | ||
1414 | struct regulator_bulk_data *consumers) | ||
1415 | { | ||
1416 | int i; | ||
1417 | int ret; | ||
1418 | |||
1419 | for (i = 0; i < num_consumers; i++) | ||
1420 | consumers[i].consumer = NULL; | ||
1421 | |||
1422 | for (i = 0; i < num_consumers; i++) { | ||
1423 | consumers[i].consumer = regulator_get(dev, | ||
1424 | consumers[i].supply); | ||
1425 | if (IS_ERR(consumers[i].consumer)) { | ||
1426 | dev_err(dev, "Failed to get supply '%s'\n", | ||
1427 | consumers[i].supply); | ||
1428 | ret = PTR_ERR(consumers[i].consumer); | ||
1429 | consumers[i].consumer = NULL; | ||
1430 | goto err; | ||
1431 | } | ||
1432 | } | ||
1433 | |||
1434 | return 0; | ||
1435 | |||
1436 | err: | ||
1437 | for (i = 0; i < num_consumers && consumers[i].consumer; i++) | ||
1438 | regulator_put(consumers[i].consumer); | ||
1439 | |||
1440 | return ret; | ||
1441 | } | ||
1442 | EXPORT_SYMBOL_GPL(regulator_bulk_get); | ||
1443 | |||
1444 | /** | ||
1445 | * regulator_bulk_enable - enable multiple regulator consumers | ||
1446 | * | ||
1447 | * @num_consumers: Number of consumers | ||
1448 | * @consumers: Consumer data; clients are stored here. | ||
1449 | * @return 0 on success, an errno on failure | ||
1450 | * | ||
1451 | * This convenience API allows consumers to enable multiple regulator | ||
1452 | * clients in a single API call. If any consumers cannot be enabled | ||
1453 | * then any others that were enabled will be disabled again prior to | ||
1454 | * return. | ||
1455 | */ | ||
1456 | int regulator_bulk_enable(int num_consumers, | ||
1457 | struct regulator_bulk_data *consumers) | ||
1458 | { | ||
1459 | int i; | ||
1460 | int ret; | ||
1461 | |||
1462 | for (i = 0; i < num_consumers; i++) { | ||
1463 | ret = regulator_enable(consumers[i].consumer); | ||
1464 | if (ret != 0) | ||
1465 | goto err; | ||
1466 | } | ||
1467 | |||
1468 | return 0; | ||
1469 | |||
1470 | err: | ||
1471 | printk(KERN_ERR "Failed to enable %s\n", consumers[i].supply); | ||
1472 | for (i = 0; i < num_consumers; i++) | ||
1473 | regulator_disable(consumers[i].consumer); | ||
1474 | |||
1475 | return ret; | ||
1476 | } | ||
1477 | EXPORT_SYMBOL_GPL(regulator_bulk_enable); | ||
1478 | |||
1479 | /** | ||
1480 | * regulator_bulk_disable - disable multiple regulator consumers | ||
1481 | * | ||
1482 | * @num_consumers: Number of consumers | ||
1483 | * @consumers: Consumer data; clients are stored here. | ||
1484 | * @return 0 on success, an errno on failure | ||
1485 | * | ||
1486 | * This convenience API allows consumers to disable multiple regulator | ||
1487 | * clients in a single API call. If any consumers cannot be enabled | ||
1488 | * then any others that were disabled will be disabled again prior to | ||
1489 | * return. | ||
1490 | */ | ||
1491 | int regulator_bulk_disable(int num_consumers, | ||
1492 | struct regulator_bulk_data *consumers) | ||
1493 | { | ||
1494 | int i; | ||
1495 | int ret; | ||
1496 | |||
1497 | for (i = 0; i < num_consumers; i++) { | ||
1498 | ret = regulator_disable(consumers[i].consumer); | ||
1499 | if (ret != 0) | ||
1500 | goto err; | ||
1501 | } | ||
1502 | |||
1503 | return 0; | ||
1504 | |||
1505 | err: | ||
1506 | printk(KERN_ERR "Failed to disable %s\n", consumers[i].supply); | ||
1507 | for (i = 0; i < num_consumers; i++) | ||
1508 | regulator_enable(consumers[i].consumer); | ||
1509 | |||
1510 | return ret; | ||
1511 | } | ||
1512 | EXPORT_SYMBOL_GPL(regulator_bulk_disable); | ||
1513 | |||
1514 | /** | ||
1515 | * regulator_bulk_free - free multiple regulator consumers | ||
1516 | * | ||
1517 | * @num_consumers: Number of consumers | ||
1518 | * @consumers: Consumer data; clients are stored here. | ||
1519 | * | ||
1520 | * This convenience API allows consumers to free multiple regulator | ||
1521 | * clients in a single API call. | ||
1522 | */ | ||
1523 | void regulator_bulk_free(int num_consumers, | ||
1524 | struct regulator_bulk_data *consumers) | ||
1525 | { | ||
1526 | int i; | ||
1527 | |||
1528 | for (i = 0; i < num_consumers; i++) { | ||
1529 | regulator_put(consumers[i].consumer); | ||
1530 | consumers[i].consumer = NULL; | ||
1531 | } | ||
1532 | } | ||
1533 | EXPORT_SYMBOL_GPL(regulator_bulk_free); | ||
1534 | |||
1535 | /** | ||
1536 | * regulator_notifier_call_chain - call regulator event notifier | ||
1537 | * @regulator: regulator source | ||
1538 | * @event: notifier block | ||
1539 | * @data: | ||
1540 | * | ||
1541 | * Called by regulator drivers to notify clients a regulator event has | ||
1542 | * occurred. We also notify regulator clients downstream. | ||
1543 | */ | ||
1544 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | ||
1545 | unsigned long event, void *data) | ||
1546 | { | ||
1547 | _notifier_call_chain(rdev, event, data); | ||
1548 | return NOTIFY_DONE; | ||
1549 | |||
1550 | } | ||
1551 | EXPORT_SYMBOL_GPL(regulator_notifier_call_chain); | ||
1552 | |||
1553 | /** | ||
1554 | * regulator_register - register regulator | ||
1555 | * @regulator: regulator source | ||
1556 | * @reg_data: private regulator data | ||
1557 | * | ||
1558 | * Called by regulator drivers to register a regulator. | ||
1559 | * Returns 0 on success. | ||
1560 | */ | ||
1561 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | ||
1562 | void *reg_data) | ||
1563 | { | ||
1564 | static atomic_t regulator_no = ATOMIC_INIT(0); | ||
1565 | struct regulator_dev *rdev; | ||
1566 | int ret; | ||
1567 | |||
1568 | if (regulator_desc == NULL) | ||
1569 | return ERR_PTR(-EINVAL); | ||
1570 | |||
1571 | if (regulator_desc->name == NULL || regulator_desc->ops == NULL) | ||
1572 | return ERR_PTR(-EINVAL); | ||
1573 | |||
1574 | if (!regulator_desc->type == REGULATOR_VOLTAGE && | ||
1575 | !regulator_desc->type == REGULATOR_CURRENT) | ||
1576 | return ERR_PTR(-EINVAL); | ||
1577 | |||
1578 | rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); | ||
1579 | if (rdev == NULL) | ||
1580 | return ERR_PTR(-ENOMEM); | ||
1581 | |||
1582 | mutex_lock(®ulator_list_mutex); | ||
1583 | |||
1584 | mutex_init(&rdev->mutex); | ||
1585 | rdev->reg_data = reg_data; | ||
1586 | rdev->owner = regulator_desc->owner; | ||
1587 | rdev->desc = regulator_desc; | ||
1588 | INIT_LIST_HEAD(&rdev->consumer_list); | ||
1589 | INIT_LIST_HEAD(&rdev->supply_list); | ||
1590 | INIT_LIST_HEAD(&rdev->list); | ||
1591 | INIT_LIST_HEAD(&rdev->slist); | ||
1592 | BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); | ||
1593 | |||
1594 | rdev->dev.class = ®ulator_class; | ||
1595 | device_initialize(&rdev->dev); | ||
1596 | snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id), | ||
1597 | "regulator_%ld_%s", | ||
1598 | (unsigned long)atomic_inc_return(®ulator_no) - 1, | ||
1599 | regulator_desc->name); | ||
1600 | |||
1601 | ret = device_add(&rdev->dev); | ||
1602 | if (ret == 0) | ||
1603 | list_add(&rdev->list, ®ulator_list); | ||
1604 | else { | ||
1605 | kfree(rdev); | ||
1606 | rdev = ERR_PTR(ret); | ||
1607 | } | ||
1608 | mutex_unlock(®ulator_list_mutex); | ||
1609 | return rdev; | ||
1610 | } | ||
1611 | EXPORT_SYMBOL_GPL(regulator_register); | ||
1612 | |||
1613 | /** | ||
1614 | * regulator_unregister - unregister regulator | ||
1615 | * @regulator: regulator source | ||
1616 | * | ||
1617 | * Called by regulator drivers to unregister a regulator. | ||
1618 | */ | ||
1619 | void regulator_unregister(struct regulator_dev *rdev) | ||
1620 | { | ||
1621 | if (rdev == NULL) | ||
1622 | return; | ||
1623 | |||
1624 | mutex_lock(®ulator_list_mutex); | ||
1625 | list_del(&rdev->list); | ||
1626 | if (rdev->supply) | ||
1627 | sysfs_remove_link(&rdev->dev.kobj, "supply"); | ||
1628 | device_unregister(&rdev->dev); | ||
1629 | mutex_unlock(®ulator_list_mutex); | ||
1630 | } | ||
1631 | EXPORT_SYMBOL_GPL(regulator_unregister); | ||
1632 | |||
1633 | /** | ||
1634 | * regulator_set_supply - set regulator supply regulator | ||
1635 | * @regulator: regulator name | ||
1636 | * @supply: supply regulator name | ||
1637 | * | ||
1638 | * Called by platform initialisation code to set the supply regulator for this | ||
1639 | * regulator. This ensures that a regulators supply will also be enabled by the | ||
1640 | * core if it's child is enabled. | ||
1641 | */ | ||
1642 | int regulator_set_supply(const char *regulator, const char *supply) | ||
1643 | { | ||
1644 | struct regulator_dev *rdev, *supply_rdev; | ||
1645 | int err; | ||
1646 | |||
1647 | if (regulator == NULL || supply == NULL) | ||
1648 | return -EINVAL; | ||
1649 | |||
1650 | mutex_lock(®ulator_list_mutex); | ||
1651 | |||
1652 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
1653 | if (!strcmp(rdev->desc->name, regulator)) | ||
1654 | goto found_regulator; | ||
1655 | } | ||
1656 | mutex_unlock(®ulator_list_mutex); | ||
1657 | return -ENODEV; | ||
1658 | |||
1659 | found_regulator: | ||
1660 | list_for_each_entry(supply_rdev, ®ulator_list, list) { | ||
1661 | if (!strcmp(supply_rdev->desc->name, supply)) | ||
1662 | goto found_supply; | ||
1663 | } | ||
1664 | mutex_unlock(®ulator_list_mutex); | ||
1665 | return -ENODEV; | ||
1666 | |||
1667 | found_supply: | ||
1668 | err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, | ||
1669 | "supply"); | ||
1670 | if (err) { | ||
1671 | printk(KERN_ERR | ||
1672 | "%s: could not add device link %s err %d\n", | ||
1673 | __func__, supply_rdev->dev.kobj.name, err); | ||
1674 | goto out; | ||
1675 | } | ||
1676 | rdev->supply = supply_rdev; | ||
1677 | list_add(&rdev->slist, &supply_rdev->supply_list); | ||
1678 | out: | ||
1679 | mutex_unlock(®ulator_list_mutex); | ||
1680 | return err; | ||
1681 | } | ||
1682 | EXPORT_SYMBOL_GPL(regulator_set_supply); | ||
1683 | |||
1684 | /** | ||
1685 | * regulator_get_supply - get regulator supply regulator | ||
1686 | * @regulator: regulator name | ||
1687 | * | ||
1688 | * Returns the supply supply regulator name or NULL if no supply regulator | ||
1689 | * exists (i.e the regulator is supplied directly from USB, Line, Battery, etc) | ||
1690 | */ | ||
1691 | const char *regulator_get_supply(const char *regulator) | ||
1692 | { | ||
1693 | struct regulator_dev *rdev; | ||
1694 | |||
1695 | if (regulator == NULL) | ||
1696 | return NULL; | ||
1697 | |||
1698 | mutex_lock(®ulator_list_mutex); | ||
1699 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
1700 | if (!strcmp(rdev->desc->name, regulator)) | ||
1701 | goto found; | ||
1702 | } | ||
1703 | mutex_unlock(®ulator_list_mutex); | ||
1704 | return NULL; | ||
1705 | |||
1706 | found: | ||
1707 | mutex_unlock(®ulator_list_mutex); | ||
1708 | if (rdev->supply) | ||
1709 | return rdev->supply->desc->name; | ||
1710 | else | ||
1711 | return NULL; | ||
1712 | } | ||
1713 | EXPORT_SYMBOL_GPL(regulator_get_supply); | ||
1714 | |||
1715 | /** | ||
1716 | * regulator_set_machine_constraints - sets regulator constraints | ||
1717 | * @regulator: regulator source | ||
1718 | * | ||
1719 | * Allows platform initialisation code to define and constrain | ||
1720 | * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: | ||
1721 | * Constraints *must* be set by platform code in order for some | ||
1722 | * regulator operations to proceed i.e. set_voltage, set_current_limit, | ||
1723 | * set_mode. | ||
1724 | */ | ||
1725 | int regulator_set_machine_constraints(const char *regulator_name, | ||
1726 | struct regulation_constraints *constraints) | ||
1727 | { | ||
1728 | struct regulator_dev *rdev; | ||
1729 | int ret = 0; | ||
1730 | |||
1731 | if (regulator_name == NULL) | ||
1732 | return -EINVAL; | ||
1733 | |||
1734 | mutex_lock(®ulator_list_mutex); | ||
1735 | |||
1736 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
1737 | if (!strcmp(regulator_name, rdev->desc->name)) | ||
1738 | goto found; | ||
1739 | } | ||
1740 | ret = -ENODEV; | ||
1741 | goto out; | ||
1742 | |||
1743 | found: | ||
1744 | mutex_lock(&rdev->mutex); | ||
1745 | rdev->constraints = constraints; | ||
1746 | |||
1747 | /* do we need to apply the constraint voltage */ | ||
1748 | if (rdev->constraints->apply_uV && | ||
1749 | rdev->constraints->min_uV == rdev->constraints->max_uV && | ||
1750 | rdev->desc->ops->set_voltage) { | ||
1751 | ret = rdev->desc->ops->set_voltage(rdev, | ||
1752 | rdev->constraints->min_uV, rdev->constraints->max_uV); | ||
1753 | if (ret < 0) { | ||
1754 | printk(KERN_ERR "%s: failed to apply %duV" | ||
1755 | " constraint\n", __func__, | ||
1756 | rdev->constraints->min_uV); | ||
1757 | rdev->constraints = NULL; | ||
1758 | goto out; | ||
1759 | } | ||
1760 | } | ||
1761 | |||
1762 | /* are we enabled at boot time by firmware / bootloader */ | ||
1763 | if (rdev->constraints->boot_on) | ||
1764 | rdev->use_count = 1; | ||
1765 | |||
1766 | /* do we need to setup our suspend state */ | ||
1767 | if (constraints->initial_state) | ||
1768 | ret = suspend_prepare(rdev, constraints->initial_state); | ||
1769 | |||
1770 | print_constraints(rdev); | ||
1771 | mutex_unlock(&rdev->mutex); | ||
1772 | |||
1773 | out: | ||
1774 | mutex_unlock(®ulator_list_mutex); | ||
1775 | return ret; | ||
1776 | } | ||
1777 | EXPORT_SYMBOL_GPL(regulator_set_machine_constraints); | ||
1778 | |||
1779 | |||
1780 | /** | ||
1781 | * regulator_set_device_supply: Bind a regulator to a symbolic supply | ||
1782 | * @regulator: regulator source | ||
1783 | * @dev: device the supply applies to | ||
1784 | * @supply: symbolic name for supply | ||
1785 | * | ||
1786 | * Allows platform initialisation code to map physical regulator | ||
1787 | * sources to symbolic names for supplies for use by devices. Devices | ||
1788 | * should use these symbolic names to request regulators, avoiding the | ||
1789 | * need to provide board-specific regulator names as platform data. | ||
1790 | */ | ||
1791 | int regulator_set_device_supply(const char *regulator, struct device *dev, | ||
1792 | const char *supply) | ||
1793 | { | ||
1794 | struct regulator_map *node; | ||
1795 | |||
1796 | if (regulator == NULL || supply == NULL) | ||
1797 | return -EINVAL; | ||
1798 | |||
1799 | node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL); | ||
1800 | if (node == NULL) | ||
1801 | return -ENOMEM; | ||
1802 | |||
1803 | node->regulator = regulator; | ||
1804 | node->dev = dev; | ||
1805 | node->supply = supply; | ||
1806 | |||
1807 | mutex_lock(®ulator_list_mutex); | ||
1808 | list_add(&node->list, ®ulator_map_list); | ||
1809 | mutex_unlock(®ulator_list_mutex); | ||
1810 | return 0; | ||
1811 | } | ||
1812 | EXPORT_SYMBOL_GPL(regulator_set_device_supply); | ||
1813 | |||
1814 | /** | ||
1815 | * regulator_suspend_prepare: prepare regulators for system wide suspend | ||
1816 | * @state: system suspend state | ||
1817 | * | ||
1818 | * Configure each regulator with it's suspend operating parameters for state. | ||
1819 | * This will usually be called by machine suspend code prior to supending. | ||
1820 | */ | ||
1821 | int regulator_suspend_prepare(suspend_state_t state) | ||
1822 | { | ||
1823 | struct regulator_dev *rdev; | ||
1824 | int ret = 0; | ||
1825 | |||
1826 | /* ON is handled by regulator active state */ | ||
1827 | if (state == PM_SUSPEND_ON) | ||
1828 | return -EINVAL; | ||
1829 | |||
1830 | mutex_lock(®ulator_list_mutex); | ||
1831 | list_for_each_entry(rdev, ®ulator_list, list) { | ||
1832 | |||
1833 | mutex_lock(&rdev->mutex); | ||
1834 | ret = suspend_prepare(rdev, state); | ||
1835 | mutex_unlock(&rdev->mutex); | ||
1836 | |||
1837 | if (ret < 0) { | ||
1838 | printk(KERN_ERR "%s: failed to prepare %s\n", | ||
1839 | __func__, rdev->desc->name); | ||
1840 | goto out; | ||
1841 | } | ||
1842 | } | ||
1843 | out: | ||
1844 | mutex_unlock(®ulator_list_mutex); | ||
1845 | return ret; | ||
1846 | } | ||
1847 | EXPORT_SYMBOL_GPL(regulator_suspend_prepare); | ||
1848 | |||
1849 | /** | ||
1850 | * rdev_get_drvdata - get rdev regulator driver data | ||
1851 | * @regulator: regulator | ||
1852 | * | ||
1853 | * Get rdev regulator driver private data. This call can be used in the | ||
1854 | * regulator driver context. | ||
1855 | */ | ||
1856 | void *rdev_get_drvdata(struct regulator_dev *rdev) | ||
1857 | { | ||
1858 | return rdev->reg_data; | ||
1859 | } | ||
1860 | EXPORT_SYMBOL_GPL(rdev_get_drvdata); | ||
1861 | |||
1862 | /** | ||
1863 | * regulator_get_drvdata - get regulator driver data | ||
1864 | * @regulator: regulator | ||
1865 | * | ||
1866 | * Get regulator driver private data. This call can be used in the consumer | ||
1867 | * driver context when non API regulator specific functions need to be called. | ||
1868 | */ | ||
1869 | void *regulator_get_drvdata(struct regulator *regulator) | ||
1870 | { | ||
1871 | return regulator->rdev->reg_data; | ||
1872 | } | ||
1873 | EXPORT_SYMBOL_GPL(regulator_get_drvdata); | ||
1874 | |||
1875 | /** | ||
1876 | * regulator_set_drvdata - set regulator driver data | ||
1877 | * @regulator: regulator | ||
1878 | * @data: data | ||
1879 | */ | ||
1880 | void regulator_set_drvdata(struct regulator *regulator, void *data) | ||
1881 | { | ||
1882 | regulator->rdev->reg_data = data; | ||
1883 | } | ||
1884 | EXPORT_SYMBOL_GPL(regulator_set_drvdata); | ||
1885 | |||
1886 | /** | ||
1887 | * regulator_get_id - get regulator ID | ||
1888 | * @regulator: regulator | ||
1889 | */ | ||
1890 | int rdev_get_id(struct regulator_dev *rdev) | ||
1891 | { | ||
1892 | return rdev->desc->id; | ||
1893 | } | ||
1894 | EXPORT_SYMBOL_GPL(rdev_get_id); | ||
1895 | |||
1896 | static int __init regulator_init(void) | ||
1897 | { | ||
1898 | printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); | ||
1899 | return class_register(®ulator_class); | ||
1900 | } | ||
1901 | |||
1902 | /* init early to allow our consumers to complete system booting */ | ||
1903 | core_initcall(regulator_init); | ||
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c new file mode 100644 index 000000000000..d31db3e14913 --- /dev/null +++ b/drivers/regulator/fixed.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * fixed.c | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License as | ||
10 | * published by the Free Software Foundation; either version 2 of the | ||
11 | * License, or (at your option) any later version. | ||
12 | * | ||
13 | * This is useful for systems with mixed controllable and | ||
14 | * non-controllable regulators, as well as for allowing testing on | ||
15 | * systems with no controllable regulators. | ||
16 | */ | ||
17 | |||
18 | #include <linux/err.h> | ||
19 | #include <linux/mutex.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/regulator/driver.h> | ||
22 | #include <linux/regulator/fixed.h> | ||
23 | |||
24 | struct fixed_voltage_data { | ||
25 | struct regulator_desc desc; | ||
26 | struct regulator_dev *dev; | ||
27 | int microvolts; | ||
28 | }; | ||
29 | |||
30 | static int fixed_voltage_is_enabled(struct regulator_dev *dev) | ||
31 | { | ||
32 | return 1; | ||
33 | } | ||
34 | |||
35 | static int fixed_voltage_enable(struct regulator_dev *dev) | ||
36 | { | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | static int fixed_voltage_get_voltage(struct regulator_dev *dev) | ||
41 | { | ||
42 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | ||
43 | |||
44 | return data->microvolts; | ||
45 | } | ||
46 | |||
47 | static struct regulator_ops fixed_voltage_ops = { | ||
48 | .is_enabled = fixed_voltage_is_enabled, | ||
49 | .enable = fixed_voltage_enable, | ||
50 | .get_voltage = fixed_voltage_get_voltage, | ||
51 | }; | ||
52 | |||
53 | static int regulator_fixed_voltage_probe(struct platform_device *pdev) | ||
54 | { | ||
55 | struct fixed_voltage_config *config = pdev->dev.platform_data; | ||
56 | struct fixed_voltage_data *drvdata; | ||
57 | int ret; | ||
58 | |||
59 | drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); | ||
60 | if (drvdata == NULL) { | ||
61 | ret = -ENOMEM; | ||
62 | goto err; | ||
63 | } | ||
64 | |||
65 | drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); | ||
66 | if (drvdata->desc.name == NULL) { | ||
67 | ret = -ENOMEM; | ||
68 | goto err; | ||
69 | } | ||
70 | drvdata->desc.type = REGULATOR_VOLTAGE; | ||
71 | drvdata->desc.owner = THIS_MODULE; | ||
72 | drvdata->desc.ops = &fixed_voltage_ops, | ||
73 | |||
74 | drvdata->microvolts = config->microvolts; | ||
75 | |||
76 | drvdata->dev = regulator_register(&drvdata->desc, drvdata); | ||
77 | if (IS_ERR(drvdata->dev)) { | ||
78 | ret = PTR_ERR(drvdata->dev); | ||
79 | goto err_name; | ||
80 | } | ||
81 | |||
82 | platform_set_drvdata(pdev, drvdata); | ||
83 | |||
84 | dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name, | ||
85 | drvdata->microvolts); | ||
86 | |||
87 | return 0; | ||
88 | |||
89 | err_name: | ||
90 | kfree(drvdata->desc.name); | ||
91 | err: | ||
92 | kfree(drvdata); | ||
93 | return ret; | ||
94 | } | ||
95 | |||
96 | static int regulator_fixed_voltage_remove(struct platform_device *pdev) | ||
97 | { | ||
98 | struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); | ||
99 | |||
100 | regulator_unregister(drvdata->dev); | ||
101 | kfree(drvdata->desc.name); | ||
102 | kfree(drvdata); | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static struct platform_driver regulator_fixed_voltage_driver = { | ||
108 | .probe = regulator_fixed_voltage_probe, | ||
109 | .remove = regulator_fixed_voltage_remove, | ||
110 | .driver = { | ||
111 | .name = "reg-fixed-voltage", | ||
112 | }, | ||
113 | }; | ||
114 | |||
115 | static int __init regulator_fixed_voltage_init(void) | ||
116 | { | ||
117 | return platform_driver_register(®ulator_fixed_voltage_driver); | ||
118 | } | ||
119 | module_init(regulator_fixed_voltage_init); | ||
120 | |||
121 | static void __exit regulator_fixed_voltage_exit(void) | ||
122 | { | ||
123 | platform_driver_unregister(®ulator_fixed_voltage_driver); | ||
124 | } | ||
125 | module_exit(regulator_fixed_voltage_exit); | ||
126 | |||
127 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
128 | MODULE_DESCRIPTION("Fixed voltage regulator"); | ||
129 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c new file mode 100644 index 000000000000..5ddb464b1c3f --- /dev/null +++ b/drivers/regulator/virtual.c | |||
@@ -0,0 +1,345 @@ | |||
1 | /* | ||
2 | * reg-virtual-consumer.c | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License as | ||
10 | * published by the Free Software Foundation; either version 2 of the | ||
11 | * License, or (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <linux/err.h> | ||
15 | #include <linux/mutex.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | #include <linux/regulator/consumer.h> | ||
18 | |||
19 | struct virtual_consumer_data { | ||
20 | struct mutex lock; | ||
21 | struct regulator *regulator; | ||
22 | int enabled; | ||
23 | int min_uV; | ||
24 | int max_uV; | ||
25 | int min_uA; | ||
26 | int max_uA; | ||
27 | unsigned int mode; | ||
28 | }; | ||
29 | |||
30 | static void update_voltage_constraints(struct virtual_consumer_data *data) | ||
31 | { | ||
32 | int ret; | ||
33 | |||
34 | if (data->min_uV && data->max_uV | ||
35 | && data->min_uV <= data->max_uV) { | ||
36 | ret = regulator_set_voltage(data->regulator, | ||
37 | data->min_uV, data->max_uV); | ||
38 | if (ret != 0) { | ||
39 | printk(KERN_ERR "regulator_set_voltage() failed: %d\n", | ||
40 | ret); | ||
41 | return; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | if (data->min_uV && data->max_uV && !data->enabled) { | ||
46 | ret = regulator_enable(data->regulator); | ||
47 | if (ret == 0) | ||
48 | data->enabled = 1; | ||
49 | else | ||
50 | printk(KERN_ERR "regulator_enable() failed: %d\n", | ||
51 | ret); | ||
52 | } | ||
53 | |||
54 | if (!(data->min_uV && data->max_uV) && data->enabled) { | ||
55 | ret = regulator_disable(data->regulator); | ||
56 | if (ret == 0) | ||
57 | data->enabled = 0; | ||
58 | else | ||
59 | printk(KERN_ERR "regulator_disable() failed: %d\n", | ||
60 | ret); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | static void update_current_limit_constraints(struct virtual_consumer_data | ||
65 | *data) | ||
66 | { | ||
67 | int ret; | ||
68 | |||
69 | if (data->max_uA | ||
70 | && data->min_uA <= data->max_uA) { | ||
71 | ret = regulator_set_current_limit(data->regulator, | ||
72 | data->min_uA, data->max_uA); | ||
73 | if (ret != 0) { | ||
74 | pr_err("regulator_set_current_limit() failed: %d\n", | ||
75 | ret); | ||
76 | return; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | if (data->max_uA && !data->enabled) { | ||
81 | ret = regulator_enable(data->regulator); | ||
82 | if (ret == 0) | ||
83 | data->enabled = 1; | ||
84 | else | ||
85 | printk(KERN_ERR "regulator_enable() failed: %d\n", | ||
86 | ret); | ||
87 | } | ||
88 | |||
89 | if (!(data->min_uA && data->max_uA) && data->enabled) { | ||
90 | ret = regulator_disable(data->regulator); | ||
91 | if (ret == 0) | ||
92 | data->enabled = 0; | ||
93 | else | ||
94 | printk(KERN_ERR "regulator_disable() failed: %d\n", | ||
95 | ret); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | static ssize_t show_min_uV(struct device *dev, | ||
100 | struct device_attribute *attr, char *buf) | ||
101 | { | ||
102 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
103 | return sprintf(buf, "%d\n", data->min_uV); | ||
104 | } | ||
105 | |||
106 | static ssize_t set_min_uV(struct device *dev, struct device_attribute *attr, | ||
107 | const char *buf, size_t count) | ||
108 | { | ||
109 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
110 | long val; | ||
111 | |||
112 | if (strict_strtol(buf, 10, &val) != 0) | ||
113 | return count; | ||
114 | |||
115 | mutex_lock(&data->lock); | ||
116 | |||
117 | data->min_uV = val; | ||
118 | update_voltage_constraints(data); | ||
119 | |||
120 | mutex_unlock(&data->lock); | ||
121 | |||
122 | return count; | ||
123 | } | ||
124 | |||
125 | static ssize_t show_max_uV(struct device *dev, | ||
126 | struct device_attribute *attr, char *buf) | ||
127 | { | ||
128 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
129 | return sprintf(buf, "%d\n", data->max_uV); | ||
130 | } | ||
131 | |||
132 | static ssize_t set_max_uV(struct device *dev, struct device_attribute *attr, | ||
133 | const char *buf, size_t count) | ||
134 | { | ||
135 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
136 | long val; | ||
137 | |||
138 | if (strict_strtol(buf, 10, &val) != 0) | ||
139 | return count; | ||
140 | |||
141 | mutex_lock(&data->lock); | ||
142 | |||
143 | data->max_uV = val; | ||
144 | update_voltage_constraints(data); | ||
145 | |||
146 | mutex_unlock(&data->lock); | ||
147 | |||
148 | return count; | ||
149 | } | ||
150 | |||
151 | static ssize_t show_min_uA(struct device *dev, | ||
152 | struct device_attribute *attr, char *buf) | ||
153 | { | ||
154 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
155 | return sprintf(buf, "%d\n", data->min_uA); | ||
156 | } | ||
157 | |||
158 | static ssize_t set_min_uA(struct device *dev, struct device_attribute *attr, | ||
159 | const char *buf, size_t count) | ||
160 | { | ||
161 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
162 | long val; | ||
163 | |||
164 | if (strict_strtol(buf, 10, &val) != 0) | ||
165 | return count; | ||
166 | |||
167 | mutex_lock(&data->lock); | ||
168 | |||
169 | data->min_uA = val; | ||
170 | update_current_limit_constraints(data); | ||
171 | |||
172 | mutex_unlock(&data->lock); | ||
173 | |||
174 | return count; | ||
175 | } | ||
176 | |||
177 | static ssize_t show_max_uA(struct device *dev, | ||
178 | struct device_attribute *attr, char *buf) | ||
179 | { | ||
180 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
181 | return sprintf(buf, "%d\n", data->max_uA); | ||
182 | } | ||
183 | |||
184 | static ssize_t set_max_uA(struct device *dev, struct device_attribute *attr, | ||
185 | const char *buf, size_t count) | ||
186 | { | ||
187 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
188 | long val; | ||
189 | |||
190 | if (strict_strtol(buf, 10, &val) != 0) | ||
191 | return count; | ||
192 | |||
193 | mutex_lock(&data->lock); | ||
194 | |||
195 | data->max_uA = val; | ||
196 | update_current_limit_constraints(data); | ||
197 | |||
198 | mutex_unlock(&data->lock); | ||
199 | |||
200 | return count; | ||
201 | } | ||
202 | |||
203 | static ssize_t show_mode(struct device *dev, | ||
204 | struct device_attribute *attr, char *buf) | ||
205 | { | ||
206 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
207 | |||
208 | switch (data->mode) { | ||
209 | case REGULATOR_MODE_FAST: | ||
210 | return sprintf(buf, "fast\n"); | ||
211 | case REGULATOR_MODE_NORMAL: | ||
212 | return sprintf(buf, "normal\n"); | ||
213 | case REGULATOR_MODE_IDLE: | ||
214 | return sprintf(buf, "idle\n"); | ||
215 | case REGULATOR_MODE_STANDBY: | ||
216 | return sprintf(buf, "standby\n"); | ||
217 | default: | ||
218 | return sprintf(buf, "unknown\n"); | ||
219 | } | ||
220 | } | ||
221 | |||
222 | static ssize_t set_mode(struct device *dev, struct device_attribute *attr, | ||
223 | const char *buf, size_t count) | ||
224 | { | ||
225 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | ||
226 | unsigned int mode; | ||
227 | int ret; | ||
228 | |||
229 | if (strncmp(buf, "fast", strlen("fast")) == 0) | ||
230 | mode = REGULATOR_MODE_FAST; | ||
231 | else if (strncmp(buf, "normal", strlen("normal")) == 0) | ||
232 | mode = REGULATOR_MODE_NORMAL; | ||
233 | else if (strncmp(buf, "idle", strlen("idle")) == 0) | ||
234 | mode = REGULATOR_MODE_IDLE; | ||
235 | else if (strncmp(buf, "standby", strlen("standby")) == 0) | ||
236 | mode = REGULATOR_MODE_STANDBY; | ||
237 | else { | ||
238 | dev_err(dev, "Configuring invalid mode\n"); | ||
239 | return count; | ||
240 | } | ||
241 | |||
242 | mutex_lock(&data->lock); | ||
243 | ret = regulator_set_mode(data->regulator, mode); | ||
244 | if (ret == 0) | ||
245 | data->mode = mode; | ||
246 | else | ||
247 | dev_err(dev, "Failed to configure mode: %d\n", ret); | ||
248 | mutex_unlock(&data->lock); | ||
249 | |||
250 | return count; | ||
251 | } | ||
252 | |||
253 | static DEVICE_ATTR(min_microvolts, 0666, show_min_uV, set_min_uV); | ||
254 | static DEVICE_ATTR(max_microvolts, 0666, show_max_uV, set_max_uV); | ||
255 | static DEVICE_ATTR(min_microamps, 0666, show_min_uA, set_min_uA); | ||
256 | static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); | ||
257 | static DEVICE_ATTR(mode, 0666, show_mode, set_mode); | ||
258 | |||
259 | struct device_attribute *attributes[] = { | ||
260 | &dev_attr_min_microvolts, | ||
261 | &dev_attr_max_microvolts, | ||
262 | &dev_attr_min_microamps, | ||
263 | &dev_attr_max_microamps, | ||
264 | &dev_attr_mode, | ||
265 | }; | ||
266 | |||
267 | static int regulator_virtual_consumer_probe(struct platform_device *pdev) | ||
268 | { | ||
269 | char *reg_id = pdev->dev.platform_data; | ||
270 | struct virtual_consumer_data *drvdata; | ||
271 | int ret, i; | ||
272 | |||
273 | drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); | ||
274 | if (drvdata == NULL) { | ||
275 | ret = -ENOMEM; | ||
276 | goto err; | ||
277 | } | ||
278 | |||
279 | mutex_init(&drvdata->lock); | ||
280 | |||
281 | drvdata->regulator = regulator_get(&pdev->dev, reg_id); | ||
282 | if (IS_ERR(drvdata->regulator)) { | ||
283 | ret = PTR_ERR(drvdata->regulator); | ||
284 | goto err; | ||
285 | } | ||
286 | |||
287 | for (i = 0; i < ARRAY_SIZE(attributes); i++) { | ||
288 | ret = device_create_file(&pdev->dev, attributes[i]); | ||
289 | if (ret != 0) | ||
290 | goto err; | ||
291 | } | ||
292 | |||
293 | drvdata->mode = regulator_get_mode(drvdata->regulator); | ||
294 | |||
295 | platform_set_drvdata(pdev, drvdata); | ||
296 | |||
297 | return 0; | ||
298 | |||
299 | err: | ||
300 | for (i = 0; i < ARRAY_SIZE(attributes); i++) | ||
301 | device_remove_file(&pdev->dev, attributes[i]); | ||
302 | kfree(drvdata); | ||
303 | return ret; | ||
304 | } | ||
305 | |||
306 | static int regulator_virtual_consumer_remove(struct platform_device *pdev) | ||
307 | { | ||
308 | struct virtual_consumer_data *drvdata = platform_get_drvdata(pdev); | ||
309 | int i; | ||
310 | |||
311 | for (i = 0; i < ARRAY_SIZE(attributes); i++) | ||
312 | device_remove_file(&pdev->dev, attributes[i]); | ||
313 | if (drvdata->enabled) | ||
314 | regulator_disable(drvdata->regulator); | ||
315 | regulator_put(drvdata->regulator); | ||
316 | |||
317 | kfree(drvdata); | ||
318 | |||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | static struct platform_driver regulator_virtual_consumer_driver = { | ||
323 | .probe = regulator_virtual_consumer_probe, | ||
324 | .remove = regulator_virtual_consumer_remove, | ||
325 | .driver = { | ||
326 | .name = "reg-virt-consumer", | ||
327 | }, | ||
328 | }; | ||
329 | |||
330 | |||
331 | static int __init regulator_virtual_consumer_init(void) | ||
332 | { | ||
333 | return platform_driver_register(®ulator_virtual_consumer_driver); | ||
334 | } | ||
335 | module_init(regulator_virtual_consumer_init); | ||
336 | |||
337 | static void __exit regulator_virtual_consumer_exit(void) | ||
338 | { | ||
339 | platform_driver_unregister(®ulator_virtual_consumer_driver); | ||
340 | } | ||
341 | module_exit(regulator_virtual_consumer_exit); | ||
342 | |||
343 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
344 | MODULE_DESCRIPTION("Virtual regulator consumer"); | ||
345 | MODULE_LICENSE("GPL"); | ||
diff --git a/include/linux/regulator/bq24022.h b/include/linux/regulator/bq24022.h new file mode 100644 index 000000000000..e84b0a9feda5 --- /dev/null +++ b/include/linux/regulator/bq24022.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * Support for TI bq24022 (bqTINY-II) Dual Input (USB/AC Adpater) | ||
3 | * 1-Cell Li-Ion Charger connected via GPIOs. | ||
4 | * | ||
5 | * Copyright (c) 2008 Philipp Zabel | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | /** | ||
14 | * bq24022_mach_info - platform data for bq24022 | ||
15 | * @gpio_nce: GPIO line connected to the nCE pin, used to enable / disable charging | ||
16 | * @gpio_iset2: GPIO line connected to the ISET2 pin, used to limit charging current to 100 mA / 500 mA | ||
17 | */ | ||
18 | struct bq24022_mach_info { | ||
19 | int gpio_nce; | ||
20 | int gpio_iset2; | ||
21 | }; | ||
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h new file mode 100644 index 000000000000..afdc4558bb94 --- /dev/null +++ b/include/linux/regulator/consumer.h | |||
@@ -0,0 +1,284 @@ | |||
1 | /* | ||
2 | * consumer.h -- SoC Regulator consumer support. | ||
3 | * | ||
4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | * Regulator Consumer Interface. | ||
13 | * | ||
14 | * A Power Management Regulator framework for SoC based devices. | ||
15 | * Features:- | ||
16 | * o Voltage and current level control. | ||
17 | * o Operating mode control. | ||
18 | * o Regulator status. | ||
19 | * o sysfs entries for showing client devices and status | ||
20 | * | ||
21 | * EXPERIMENTAL FEATURES: | ||
22 | * Dynamic Regulator operating Mode Switching (DRMS) - allows regulators | ||
23 | * to use most efficient operating mode depending upon voltage and load and | ||
24 | * is transparent to client drivers. | ||
25 | * | ||
26 | * e.g. Devices x,y,z share regulator r. Device x and y draw 20mA each during | ||
27 | * IO and 1mA at idle. Device z draws 100mA when under load and 5mA when | ||
28 | * idling. Regulator r has > 90% efficiency in NORMAL mode at loads > 100mA | ||
29 | * but this drops rapidly to 60% when below 100mA. Regulator r has > 90% | ||
30 | * efficiency in IDLE mode at loads < 10mA. Thus regulator r will operate | ||
31 | * in normal mode for loads > 10mA and in IDLE mode for load <= 10mA. | ||
32 | * | ||
33 | */ | ||
34 | |||
35 | #ifndef __LINUX_REGULATOR_CONSUMER_H_ | ||
36 | #define __LINUX_REGULATOR_CONSUMER_H_ | ||
37 | |||
38 | /* | ||
39 | * Regulator operating modes. | ||
40 | * | ||
41 | * Regulators can run in a variety of different operating modes depending on | ||
42 | * output load. This allows further system power savings by selecting the | ||
43 | * best (and most efficient) regulator mode for a desired load. | ||
44 | * | ||
45 | * Most drivers will only care about NORMAL. The modes below are generic and | ||
46 | * will probably not match the naming convention of your regulator data sheet | ||
47 | * but should match the use cases in the datasheet. | ||
48 | * | ||
49 | * In order of power efficiency (least efficient at top). | ||
50 | * | ||
51 | * Mode Description | ||
52 | * FAST Regulator can handle fast changes in it's load. | ||
53 | * e.g. useful in CPU voltage & frequency scaling where | ||
54 | * load can quickly increase with CPU frequency increases. | ||
55 | * | ||
56 | * NORMAL Normal regulator power supply mode. Most drivers will | ||
57 | * use this mode. | ||
58 | * | ||
59 | * IDLE Regulator runs in a more efficient mode for light | ||
60 | * loads. Can be used for devices that have a low power | ||
61 | * requirement during periods of inactivity. This mode | ||
62 | * may be more noisy than NORMAL and may not be able | ||
63 | * to handle fast load switching. | ||
64 | * | ||
65 | * STANDBY Regulator runs in the most efficient mode for very | ||
66 | * light loads. Can be used by devices when they are | ||
67 | * in a sleep/standby state. This mode is likely to be | ||
68 | * the most noisy and may not be able to handle fast load | ||
69 | * switching. | ||
70 | * | ||
71 | * NOTE: Most regulators will only support a subset of these modes. Some | ||
72 | * will only just support NORMAL. | ||
73 | * | ||
74 | * These modes can be OR'ed together to make up a mask of valid register modes. | ||
75 | */ | ||
76 | |||
77 | #define REGULATOR_MODE_FAST 0x1 | ||
78 | #define REGULATOR_MODE_NORMAL 0x2 | ||
79 | #define REGULATOR_MODE_IDLE 0x4 | ||
80 | #define REGULATOR_MODE_STANDBY 0x8 | ||
81 | |||
82 | /* | ||
83 | * Regulator notifier events. | ||
84 | * | ||
85 | * UNDER_VOLTAGE Regulator output is under voltage. | ||
86 | * OVER_CURRENT Regulator output current is too high. | ||
87 | * REGULATION_OUT Regulator output is out of regulation. | ||
88 | * FAIL Regulator output has failed. | ||
89 | * OVER_TEMP Regulator over temp. | ||
90 | * FORCE_DISABLE Regulator shut down by software. | ||
91 | * | ||
92 | * NOTE: These events can be OR'ed together when passed into handler. | ||
93 | */ | ||
94 | |||
95 | #define REGULATOR_EVENT_UNDER_VOLTAGE 0x01 | ||
96 | #define REGULATOR_EVENT_OVER_CURRENT 0x02 | ||
97 | #define REGULATOR_EVENT_REGULATION_OUT 0x04 | ||
98 | #define REGULATOR_EVENT_FAIL 0x08 | ||
99 | #define REGULATOR_EVENT_OVER_TEMP 0x10 | ||
100 | #define REGULATOR_EVENT_FORCE_DISABLE 0x20 | ||
101 | |||
102 | struct regulator; | ||
103 | |||
104 | /** | ||
105 | * struct regulator_bulk_data - Data used for bulk regulator operations. | ||
106 | * | ||
107 | * @supply The name of the supply. Initialised by the user before | ||
108 | * using the bulk regulator APIs. | ||
109 | * @consumer The regulator consumer for the supply. This will be managed | ||
110 | * by the bulk API. | ||
111 | * | ||
112 | * The regulator APIs provide a series of regulator_bulk_() API calls as | ||
113 | * a convenience to consumers which require multiple supplies. This | ||
114 | * structure is used to manage data for these calls. | ||
115 | */ | ||
116 | struct regulator_bulk_data { | ||
117 | const char *supply; | ||
118 | struct regulator *consumer; | ||
119 | }; | ||
120 | |||
121 | #if defined(CONFIG_REGULATOR) | ||
122 | |||
123 | /* regulator get and put */ | ||
124 | struct regulator *__must_check regulator_get(struct device *dev, | ||
125 | const char *id); | ||
126 | void regulator_put(struct regulator *regulator); | ||
127 | |||
128 | /* regulator output control and status */ | ||
129 | int regulator_enable(struct regulator *regulator); | ||
130 | int regulator_disable(struct regulator *regulator); | ||
131 | int regulator_force_disable(struct regulator *regulator); | ||
132 | int regulator_is_enabled(struct regulator *regulator); | ||
133 | |||
134 | int regulator_bulk_get(struct device *dev, int num_consumers, | ||
135 | struct regulator_bulk_data *consumers); | ||
136 | int regulator_bulk_enable(int num_consumers, | ||
137 | struct regulator_bulk_data *consumers); | ||
138 | int regulator_bulk_disable(int num_consumers, | ||
139 | struct regulator_bulk_data *consumers); | ||
140 | void regulator_bulk_free(int num_consumers, | ||
141 | struct regulator_bulk_data *consumers); | ||
142 | |||
143 | int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); | ||
144 | int regulator_get_voltage(struct regulator *regulator); | ||
145 | int regulator_set_current_limit(struct regulator *regulator, | ||
146 | int min_uA, int max_uA); | ||
147 | int regulator_get_current_limit(struct regulator *regulator); | ||
148 | |||
149 | int regulator_set_mode(struct regulator *regulator, unsigned int mode); | ||
150 | unsigned int regulator_get_mode(struct regulator *regulator); | ||
151 | int regulator_set_optimum_mode(struct regulator *regulator, int load_uA); | ||
152 | |||
153 | /* regulator notifier block */ | ||
154 | int regulator_register_notifier(struct regulator *regulator, | ||
155 | struct notifier_block *nb); | ||
156 | int regulator_unregister_notifier(struct regulator *regulator, | ||
157 | struct notifier_block *nb); | ||
158 | |||
159 | /* driver data - core doesn't touch */ | ||
160 | void *regulator_get_drvdata(struct regulator *regulator); | ||
161 | void regulator_set_drvdata(struct regulator *regulator, void *data); | ||
162 | |||
163 | #else | ||
164 | |||
165 | /* | ||
166 | * Make sure client drivers will still build on systems with no software | ||
167 | * controllable voltage or current regulators. | ||
168 | */ | ||
169 | static inline struct regulator *__must_check regulator_get(struct device *dev, | ||
170 | const char *id) | ||
171 | { | ||
172 | /* Nothing except the stubbed out regulator API should be | ||
173 | * looking at the value except to check if it is an error | ||
174 | * value so the actual return value doesn't matter. | ||
175 | */ | ||
176 | return (struct regulator *)id; | ||
177 | } | ||
178 | static inline void regulator_put(struct regulator *regulator) | ||
179 | { | ||
180 | } | ||
181 | |||
182 | static inline int regulator_enable(struct regulator *regulator) | ||
183 | { | ||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static inline int regulator_disable(struct regulator *regulator) | ||
188 | { | ||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | static inline int regulator_is_enabled(struct regulator *regulator) | ||
193 | { | ||
194 | return 1; | ||
195 | } | ||
196 | |||
197 | static inline int regulator_bulk_get(struct device *dev, | ||
198 | int num_consumers, | ||
199 | struct regulator_bulk_data *consumers) | ||
200 | { | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | static inline int regulator_bulk_enable(int num_consumers, | ||
205 | struct regulator_bulk_data *consumers) | ||
206 | { | ||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static inline int regulator_bulk_disable(int num_consumers, | ||
211 | struct regulator_bulk_data *consumers) | ||
212 | { | ||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | static inline void regulator_bulk_free(int num_consumers, | ||
217 | struct regulator_bulk_data *consumers) | ||
218 | { | ||
219 | } | ||
220 | |||
221 | static inline int regulator_set_voltage(struct regulator *regulator, | ||
222 | int min_uV, int max_uV) | ||
223 | { | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | static inline int regulator_get_voltage(struct regulator *regulator) | ||
228 | { | ||
229 | return 0; | ||
230 | } | ||
231 | |||
232 | static inline int regulator_set_current_limit(struct regulator *regulator, | ||
233 | int min_uA, int max_uA) | ||
234 | { | ||
235 | return 0; | ||
236 | } | ||
237 | |||
238 | static inline int regulator_get_current_limit(struct regulator *regulator) | ||
239 | { | ||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | static inline int regulator_set_mode(struct regulator *regulator, | ||
244 | unsigned int mode) | ||
245 | { | ||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | static inline unsigned int regulator_get_mode(struct regulator *regulator) | ||
250 | { | ||
251 | return REGULATOR_MODE_NORMAL; | ||
252 | } | ||
253 | |||
254 | static inline int regulator_set_optimum_mode(struct regulator *regulator, | ||
255 | int load_uA) | ||
256 | { | ||
257 | return REGULATOR_MODE_NORMAL; | ||
258 | } | ||
259 | |||
260 | static inline int regulator_register_notifier(struct regulator *regulator, | ||
261 | struct notifier_block *nb) | ||
262 | { | ||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | static inline int regulator_unregister_notifier(struct regulator *regulator, | ||
267 | struct notifier_block *nb) | ||
268 | { | ||
269 | return 0; | ||
270 | } | ||
271 | |||
272 | static inline void *regulator_get_drvdata(struct regulator *regulator) | ||
273 | { | ||
274 | return NULL; | ||
275 | } | ||
276 | |||
277 | static inline void regulator_set_drvdata(struct regulator *regulator, | ||
278 | void *data) | ||
279 | { | ||
280 | } | ||
281 | |||
282 | #endif | ||
283 | |||
284 | #endif | ||
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h new file mode 100644 index 000000000000..1d712c7172a2 --- /dev/null +++ b/include/linux/regulator/driver.h | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * driver.h -- SoC Regulator driver support. | ||
3 | * | ||
4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | * Regulator Driver Interface. | ||
13 | */ | ||
14 | |||
15 | #ifndef __LINUX_REGULATOR_DRIVER_H_ | ||
16 | #define __LINUX_REGULATOR_DRIVER_H_ | ||
17 | |||
18 | #include <linux/device.h> | ||
19 | #include <linux/regulator/consumer.h> | ||
20 | |||
21 | struct regulator_constraints; | ||
22 | struct regulator_dev; | ||
23 | |||
24 | /** | ||
25 | * struct regulator_ops - regulator operations. | ||
26 | * | ||
27 | * This struct describes regulator operations. | ||
28 | */ | ||
29 | struct regulator_ops { | ||
30 | |||
31 | /* get/set regulator voltage */ | ||
32 | int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV); | ||
33 | int (*get_voltage) (struct regulator_dev *); | ||
34 | |||
35 | /* get/set regulator current */ | ||
36 | int (*set_current_limit) (struct regulator_dev *, | ||
37 | int min_uA, int max_uA); | ||
38 | int (*get_current_limit) (struct regulator_dev *); | ||
39 | |||
40 | /* enable/disable regulator */ | ||
41 | int (*enable) (struct regulator_dev *); | ||
42 | int (*disable) (struct regulator_dev *); | ||
43 | int (*is_enabled) (struct regulator_dev *); | ||
44 | |||
45 | /* get/set regulator operating mode (defined in regulator.h) */ | ||
46 | int (*set_mode) (struct regulator_dev *, unsigned int mode); | ||
47 | unsigned int (*get_mode) (struct regulator_dev *); | ||
48 | |||
49 | /* get most efficient regulator operating mode for load */ | ||
50 | unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, | ||
51 | int output_uV, int load_uA); | ||
52 | |||
53 | /* the operations below are for configuration of regulator state when | ||
54 | * it's parent PMIC enters a global STANBY/HIBERNATE state */ | ||
55 | |||
56 | /* set regulator suspend voltage */ | ||
57 | int (*set_suspend_voltage) (struct regulator_dev *, int uV); | ||
58 | |||
59 | /* enable/disable regulator in suspend state */ | ||
60 | int (*set_suspend_enable) (struct regulator_dev *); | ||
61 | int (*set_suspend_disable) (struct regulator_dev *); | ||
62 | |||
63 | /* set regulator suspend operating mode (defined in regulator.h) */ | ||
64 | int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); | ||
65 | }; | ||
66 | |||
67 | /* | ||
68 | * Regulators can either control voltage or current. | ||
69 | */ | ||
70 | enum regulator_type { | ||
71 | REGULATOR_VOLTAGE, | ||
72 | REGULATOR_CURRENT, | ||
73 | }; | ||
74 | |||
75 | /** | ||
76 | * struct regulator_desc - Regulator descriptor | ||
77 | * | ||
78 | */ | ||
79 | struct regulator_desc { | ||
80 | const char *name; | ||
81 | int id; | ||
82 | struct regulator_ops *ops; | ||
83 | int irq; | ||
84 | enum regulator_type type; | ||
85 | struct module *owner; | ||
86 | }; | ||
87 | |||
88 | |||
89 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | ||
90 | void *reg_data); | ||
91 | void regulator_unregister(struct regulator_dev *rdev); | ||
92 | |||
93 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | ||
94 | unsigned long event, void *data); | ||
95 | |||
96 | void *rdev_get_drvdata(struct regulator_dev *rdev); | ||
97 | int rdev_get_id(struct regulator_dev *rdev); | ||
98 | |||
99 | #endif | ||
diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h new file mode 100644 index 000000000000..1387a5d2190e --- /dev/null +++ b/include/linux/regulator/fixed.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* | ||
2 | * fixed.h | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License as | ||
10 | * published by the Free Software Foundation; either version 2 of the | ||
11 | * License, or (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #ifndef __REGULATOR_FIXED_H | ||
15 | #define __REGULATOR_FIXED_H | ||
16 | |||
17 | struct fixed_voltage_config { | ||
18 | const char *supply_name; | ||
19 | int microvolts; | ||
20 | }; | ||
21 | |||
22 | #endif | ||
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h new file mode 100644 index 000000000000..11e737dbfcf2 --- /dev/null +++ b/include/linux/regulator/machine.h | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * machine.h -- SoC Regulator support, machine/board driver API. | ||
3 | * | ||
4 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | * Regulator Machine/Board Interface. | ||
13 | */ | ||
14 | |||
15 | #ifndef __LINUX_REGULATOR_MACHINE_H_ | ||
16 | #define __LINUX_REGULATOR_MACHINE_H_ | ||
17 | |||
18 | #include <linux/regulator/consumer.h> | ||
19 | #include <linux/suspend.h> | ||
20 | |||
21 | struct regulator; | ||
22 | |||
23 | /* | ||
24 | * Regulator operation constraint flags. These flags are used to enable | ||
25 | * certain regulator operations and can be OR'ed together. | ||
26 | * | ||
27 | * VOLTAGE: Regulator output voltage can be changed by software on this | ||
28 | * board/machine. | ||
29 | * CURRENT: Regulator output current can be changed by software on this | ||
30 | * board/machine. | ||
31 | * MODE: Regulator operating mode can be changed by software on this | ||
32 | * board/machine. | ||
33 | * STATUS: Regulator can be enabled and disabled. | ||
34 | * DRMS: Dynamic Regulator Mode Switching is enabled for this regulator. | ||
35 | */ | ||
36 | |||
37 | #define REGULATOR_CHANGE_VOLTAGE 0x1 | ||
38 | #define REGULATOR_CHANGE_CURRENT 0x2 | ||
39 | #define REGULATOR_CHANGE_MODE 0x4 | ||
40 | #define REGULATOR_CHANGE_STATUS 0x8 | ||
41 | #define REGULATOR_CHANGE_DRMS 0x10 | ||
42 | |||
43 | /** | ||
44 | * struct regulator_state - regulator state during low power syatem states | ||
45 | * | ||
46 | * This describes a regulators state during a system wide low power state. | ||
47 | */ | ||
48 | struct regulator_state { | ||
49 | int uV; /* suspend voltage */ | ||
50 | unsigned int mode; /* suspend regulator operating mode */ | ||
51 | int enabled; /* is regulator enabled in this suspend state */ | ||
52 | }; | ||
53 | |||
54 | /** | ||
55 | * struct regulation_constraints - regulator operating constraints. | ||
56 | * | ||
57 | * This struct describes regulator and board/machine specific constraints. | ||
58 | */ | ||
59 | struct regulation_constraints { | ||
60 | |||
61 | char *name; | ||
62 | |||
63 | /* voltage output range (inclusive) - for voltage control */ | ||
64 | int min_uV; | ||
65 | int max_uV; | ||
66 | |||
67 | /* current output range (inclusive) - for current control */ | ||
68 | int min_uA; | ||
69 | int max_uA; | ||
70 | |||
71 | /* valid regulator operating modes for this machine */ | ||
72 | unsigned int valid_modes_mask; | ||
73 | |||
74 | /* valid operations for regulator on this machine */ | ||
75 | unsigned int valid_ops_mask; | ||
76 | |||
77 | /* regulator input voltage - only if supply is another regulator */ | ||
78 | int input_uV; | ||
79 | |||
80 | /* regulator suspend states for global PMIC STANDBY/HIBERNATE */ | ||
81 | struct regulator_state state_disk; | ||
82 | struct regulator_state state_mem; | ||
83 | struct regulator_state state_standby; | ||
84 | suspend_state_t initial_state; /* suspend state to set at init */ | ||
85 | |||
86 | /* constriant flags */ | ||
87 | unsigned always_on:1; /* regulator never off when system is on */ | ||
88 | unsigned boot_on:1; /* bootloader/firmware enabled regulator */ | ||
89 | unsigned apply_uV:1; /* apply uV constraint iff min == max */ | ||
90 | }; | ||
91 | |||
92 | int regulator_set_supply(const char *regulator, const char *regulator_supply); | ||
93 | |||
94 | const char *regulator_get_supply(const char *regulator); | ||
95 | |||
96 | int regulator_set_machine_constraints(const char *regulator, | ||
97 | struct regulation_constraints *constraints); | ||
98 | |||
99 | int regulator_set_device_supply(const char *regulator, struct device *dev, | ||
100 | const char *supply); | ||
101 | |||
102 | int regulator_suspend_prepare(suspend_state_t state); | ||
103 | |||
104 | #endif | ||