]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
af41e8db PM |
2 | /* |
3 | * Copyright (C) 2014-2015 Samsung Electronics | |
4 | * Przemyslaw Marczak <[email protected]> | |
af41e8db PM |
5 | */ |
6 | ||
7 | #ifndef _INCLUDE_REGULATOR_H_ | |
8 | #define _INCLUDE_REGULATOR_H_ | |
9 | ||
401d1c4f SG |
10 | struct udevice; |
11 | ||
af41e8db PM |
12 | /** |
13 | * U-Boot Voltage/Current Regulator | |
14 | * ================================ | |
15 | * | |
16 | * The regulator API is based on a driver model, with the device tree support. | |
17 | * And this header describes the functions and data types for the uclass id: | |
18 | * 'UCLASS_REGULATOR' and the regulator driver API. | |
19 | * | |
20 | * The regulator uclass - is based on uclass platform data which is allocated, | |
caa4daa2 SG |
21 | * automatically for each regulator device on bind and 'dev->uclass_plat' |
22 | * points to it. The data type is: 'struct dm_regulator_uclass_plat'. | |
af41e8db PM |
23 | * The uclass file: 'drivers/power/regulator/regulator-uclass.c' |
24 | * | |
25 | * The regulator device - is based on driver's model 'struct udevice'. | |
26 | * The API can use regulator name in two meanings: | |
27 | * - devname - the regulator device's name: 'dev->name' | |
caa4daa2 SG |
28 | * - platname - the device's plat's name. So in the code it looks like: |
29 | * 'uc_pdata = dev->uclass_plat'; 'name = uc_pdata->name'. | |
af41e8db PM |
30 | * |
31 | * The regulator device driver - provide an implementation of uclass operations | |
32 | * pointed by 'dev->driver->ops' as a struct of type 'struct dm_regulator_ops'. | |
33 | * | |
34 | * To proper bind the regulator device, the device tree node should provide | |
35 | * regulator constraints, like in the example below: | |
36 | * | |
37 | * ldo1 { | |
3b880757 | 38 | * regulator-name = "VDD_MMC_1.8V"; (must be unique for proper bind) |
af41e8db PM |
39 | * regulator-min-microvolt = <1000000>; (optional) |
40 | * regulator-max-microvolt = <1000000>; (optional) | |
41 | * regulator-min-microamp = <1000>; (optional) | |
42 | * regulator-max-microamp = <1000>; (optional) | |
43 | * regulator-always-on; (optional) | |
44 | * regulator-boot-on; (optional) | |
45 | * }; | |
46 | * | |
3b880757 PM |
47 | * Note: For the proper operation, at least name constraint is needed, since |
48 | * it can be used when calling regulator_get_by_platname(). And the mandatory | |
49 | * rule for this name is, that it must be globally unique for the single dts. | |
40ade2ce | 50 | * If regulator-name property is not provided, node name will be chosen. |
af41e8db PM |
51 | * |
52 | * Regulator bind: | |
a2703ce1 | 53 | * For each regulator device, the device_bind() should be called with passed |
af41e8db | 54 | * device tree offset. This is required for this uclass's '.post_bind' method, |
3b880757 | 55 | * which does the scan on the device node, for the 'regulator-name' constraint. |
af41e8db PM |
56 | * If the parent is not a PMIC device, and the child is not bind by function: |
57 | * 'pmic_bind_childs()', then it's recommended to bind the device by call to | |
2e3f1ff6 | 58 | * dm_scan_fdt_dev() - this is usually done automatically for bus devices, |
af41e8db | 59 | * as a post bind method. |
3b880757 PM |
60 | * |
61 | * Regulator get: | |
af41e8db | 62 | * Having the device's name constraint, we can call regulator_by_platname(), |
3b880757 | 63 | * to find the required regulator. Before return, the regulator is probed, |
af41e8db PM |
64 | * and the rest of its constraints are put into the device's uclass platform |
65 | * data, by the uclass regulator '.pre_probe' method. | |
66 | * | |
67 | * For more info about PMIC bind, please refer to file: 'include/power/pmic.h' | |
68 | * | |
69 | * Note: | |
70 | * Please do not use the device_bind_by_name() function, since it pass '-1' as | |
71 | * device node offset - and the bind will fail on uclass .post_bind method, | |
72 | * because of missing 'regulator-name' constraint. | |
73 | * | |
74 | * | |
75 | * Fixed Voltage/Current Regulator | |
76 | * =============================== | |
77 | * | |
78 | * When fixed voltage regulator is needed, then enable the config: | |
79 | * - CONFIG_DM_REGULATOR_FIXED | |
80 | * | |
81 | * The driver file: 'drivers/power/regulator/fixed.c', provides basic support | |
82 | * for control the GPIO, and return the device tree constraint values. | |
83 | * | |
84 | * To bind the fixed voltage regulator device, we usually use a 'simple-bus' | |
85 | * node as a parent. And 'regulator-fixed' for the driver compatible. This is | |
86 | * the same as in the kernel. The example node of fixed regulator: | |
87 | * | |
88 | * simple-bus { | |
89 | * compatible = "simple-bus"; | |
90 | * #address-cells = <1>; | |
91 | * #size-cells = <0>; | |
92 | * | |
93 | * blue_led { | |
94 | * compatible = "regulator-fixed"; | |
95 | * regulator-name = "VDD_LED_3.3V"; | |
96 | * regulator-min-microvolt = <3300000>; | |
97 | * regulator-max-microvolt = <3300000>; | |
98 | * gpio = <&gpc1 0 GPIO_ACTIVE_LOW>; | |
99 | * }; | |
100 | * }; | |
101 | * | |
102 | * The fixed regulator devices also provide regulator uclass platform data. And | |
103 | * devices bound from such node, can use the regulator drivers API. | |
104 | */ | |
105 | ||
106 | /* enum regulator_type - used for regulator_*() variant calls */ | |
107 | enum regulator_type { | |
108 | REGULATOR_TYPE_LDO = 0, | |
109 | REGULATOR_TYPE_BUCK, | |
110 | REGULATOR_TYPE_DVS, | |
111 | REGULATOR_TYPE_FIXED, | |
477dfe2f | 112 | REGULATOR_TYPE_GPIO, |
af41e8db PM |
113 | REGULATOR_TYPE_OTHER, |
114 | }; | |
115 | ||
116 | /** | |
117 | * struct dm_regulator_mode - this structure holds an information about | |
118 | * each regulator operation mode. Probably in most cases - an array. | |
119 | * This will be probably a driver-static data, since it is device-specific. | |
120 | * | |
121 | * @id - a driver-specific mode id | |
122 | * @register_value - a driver-specific value for its mode id | |
123 | * @name - the name of mode - used for regulator command | |
124 | * Note: | |
125 | * The field 'id', should be always a positive number, since the negative values | |
126 | * are reserved for the errno numbers when returns the mode id. | |
127 | */ | |
128 | struct dm_regulator_mode { | |
129 | int id; /* Set only as >= 0 (negative value is reserved for errno) */ | |
130 | int register_value; | |
131 | const char *name; | |
132 | }; | |
133 | ||
7837ceab SG |
134 | enum regulator_flag { |
135 | REGULATOR_FLAG_AUTOSET_UV = 1 << 0, | |
136 | REGULATOR_FLAG_AUTOSET_UA = 1 << 1, | |
d99fb64a | 137 | REGULATOR_FLAG_AUTOSET_DONE = 1 << 2, |
7837ceab SG |
138 | }; |
139 | ||
af41e8db | 140 | /** |
caa4daa2 | 141 | * struct dm_regulator_uclass_plat - pointed by dev->uclass_plat, and |
af41e8db PM |
142 | * allocated on each regulator bind. This structure holds an information |
143 | * about each regulator's constraints and supported operation modes. | |
144 | * There is no "step" voltage value - so driver should take care of this. | |
145 | * | |
146 | * @type - one of 'enum regulator_type' | |
147 | * @mode - pointer to the regulator mode (array if more than one) | |
148 | * @mode_count - number of '.mode' entries | |
149 | * @min_uV* - minimum voltage (micro Volts) | |
150 | * @max_uV* - maximum voltage (micro Volts) | |
151 | * @min_uA* - minimum amperage (micro Amps) | |
152 | * @max_uA* - maximum amperage (micro Amps) | |
153 | * @always_on* - bool type, true or false | |
154 | * @boot_on* - bool type, true or false | |
fec8c900 | 155 | * @force_off* - bool type, true or false |
7837ceab | 156 | * TODO([email protected]): Consider putting the above two into @flags |
e66d1cb3 | 157 | * @ramp_delay - Time to settle down after voltage change (unit: uV/us) |
7837ceab | 158 | * @flags: - flags value (see REGULATOR_FLAG_...) |
af41e8db | 159 | * @name** - fdt regulator name - should be taken from the device tree |
34514b8b K |
160 | * ctrl_reg: - Control register offset used to enable/disable regulator |
161 | * volt_reg: - register offset for writing voltage vsel values | |
af41e8db PM |
162 | * |
163 | * Note: | |
164 | * * - set automatically on device probe by the uclass's '.pre_probe' method. | |
165 | * ** - set automatically on device bind by the uclass's '.post_bind' method. | |
166 | * The constraints: type, mode, mode_count, can be set by device driver, e.g. | |
167 | * by the driver '.probe' method. | |
168 | */ | |
caa4daa2 | 169 | struct dm_regulator_uclass_plat { |
af41e8db PM |
170 | enum regulator_type type; |
171 | struct dm_regulator_mode *mode; | |
172 | int mode_count; | |
173 | int min_uV; | |
174 | int max_uV; | |
11406b8f | 175 | int init_uV; |
af41e8db PM |
176 | int min_uA; |
177 | int max_uA; | |
e66d1cb3 | 178 | unsigned int ramp_delay; |
af41e8db PM |
179 | bool always_on; |
180 | bool boot_on; | |
fec8c900 | 181 | bool force_off; |
af41e8db | 182 | const char *name; |
7837ceab | 183 | int flags; |
34514b8b K |
184 | u8 ctrl_reg; |
185 | u8 volt_reg; | |
11406b8f JC |
186 | bool suspend_on; |
187 | u32 suspend_uV; | |
af41e8db PM |
188 | }; |
189 | ||
190 | /* Regulator device operations */ | |
191 | struct dm_regulator_ops { | |
192 | /** | |
193 | * The regulator output value function calls operates on a micro Volts. | |
194 | * | |
195 | * get/set_value - get/set output value of the given output number | |
196 | * @dev - regulator device | |
197 | * Sets: | |
198 | * @uV - set the output value [micro Volts] | |
1757df46 | 199 | * @return output value [uV] on success or negative errno if fail. |
af41e8db PM |
200 | */ |
201 | int (*get_value)(struct udevice *dev); | |
202 | int (*set_value)(struct udevice *dev, int uV); | |
203 | ||
11406b8f JC |
204 | /** |
205 | * The regulator suspend output value function calls operates | |
206 | * on a micro Volts. | |
207 | * | |
208 | * get/set_suspen_value - get/set suspend mode output value | |
209 | * @dev - regulator device | |
210 | * Sets: | |
211 | * @uV - set the suspend output value [micro Volts] | |
212 | * @return output value [uV] on success or negative errno if fail. | |
213 | */ | |
214 | int (*set_suspend_value)(struct udevice *dev, int uV); | |
215 | int (*get_suspend_value)(struct udevice *dev); | |
216 | ||
af41e8db PM |
217 | /** |
218 | * The regulator output current function calls operates on a micro Amps. | |
219 | * | |
220 | * get/set_current - get/set output current of the given output number | |
221 | * @dev - regulator device | |
222 | * Sets: | |
223 | * @uA - set the output current [micro Amps] | |
1757df46 | 224 | * @return output value [uA] on success or negative errno if fail. |
af41e8db PM |
225 | */ |
226 | int (*get_current)(struct udevice *dev); | |
227 | int (*set_current)(struct udevice *dev, int uA); | |
228 | ||
229 | /** | |
230 | * The most basic feature of the regulator output is its enable state. | |
231 | * | |
232 | * get/set_enable - get/set enable state of the given output number | |
233 | * @dev - regulator device | |
234 | * Sets: | |
235 | * @enable - set true - enable or false - disable | |
06bdf600 | 236 | * @return true/false for get or -errno if fail; 0 / -errno for set. |
af41e8db | 237 | */ |
06bdf600 | 238 | int (*get_enable)(struct udevice *dev); |
af41e8db PM |
239 | int (*set_enable)(struct udevice *dev, bool enable); |
240 | ||
11406b8f JC |
241 | /** |
242 | * The most basic feature of the regulator output is its enable state | |
243 | * in suspend mode. | |
244 | * | |
245 | * get/set_suspend_enable - get/set enable state of the suspend output | |
246 | * @dev - regulator device | |
247 | * Sets: | |
248 | * @enable - set true - enable or false - disable | |
249 | * @return true/false for get or -errno if fail; 0 / -errno for set. | |
250 | */ | |
251 | int (*set_suspend_enable)(struct udevice *dev, bool enable); | |
252 | int (*get_suspend_enable)(struct udevice *dev); | |
253 | ||
af41e8db | 254 | /** |
1757df46 | 255 | * The 'get/set_mode()' function calls should operate on a driver- |
3b880757 PM |
256 | * specific mode id definitions, which should be found in: |
257 | * field 'id' of struct dm_regulator_mode. | |
af41e8db PM |
258 | * |
259 | * get/set_mode - get/set operation mode of the given output number | |
260 | * @dev - regulator device | |
261 | * Sets | |
262 | * @mode_id - set output mode id (struct dm_regulator_mode->id) | |
1757df46 | 263 | * @return id/0 for get/set on success or negative errno if fail. |
af41e8db PM |
264 | * Note: |
265 | * The field 'id' of struct type 'dm_regulator_mode', should be always | |
3b880757 | 266 | * a positive number, since the negative is reserved for the error. |
af41e8db PM |
267 | */ |
268 | int (*get_mode)(struct udevice *dev); | |
269 | int (*set_mode)(struct udevice *dev, int mode_id); | |
270 | }; | |
271 | ||
16cc5ad0 | 272 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
af41e8db PM |
273 | /** |
274 | * regulator_mode: returns a pointer to the array of regulator mode info | |
275 | * | |
276 | * @dev - pointer to the regulator device | |
277 | * @modep - pointer to the returned mode info array | |
185f812c | 278 | * Return: - count of modep entries on success or negative errno if fail. |
af41e8db PM |
279 | */ |
280 | int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep); | |
281 | ||
282 | /** | |
283 | * regulator_get_value: get microvoltage voltage value of a given regulator | |
284 | * | |
285 | * @dev - pointer to the regulator device | |
185f812c | 286 | * Return: - positive output value [uV] on success or negative errno if fail. |
af41e8db PM |
287 | */ |
288 | int regulator_get_value(struct udevice *dev); | |
289 | ||
290 | /** | |
291 | * regulator_set_value: set the microvoltage value of a given regulator. | |
292 | * | |
293 | * @dev - pointer to the regulator device | |
294 | * @uV - the output value to set [micro Volts] | |
185f812c | 295 | * Return: - 0 on success or -errno val if fails |
af41e8db PM |
296 | */ |
297 | int regulator_set_value(struct udevice *dev, int uV); | |
298 | ||
11406b8f JC |
299 | /** |
300 | * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator. | |
301 | * | |
302 | * @dev - pointer to the regulator device | |
303 | * @uV - the output suspend value to set [micro Volts] | |
185f812c | 304 | * Return: - 0 on success or -errno val if fails |
11406b8f JC |
305 | */ |
306 | int regulator_set_suspend_value(struct udevice *dev, int uV); | |
307 | ||
308 | /** | |
309 | * regulator_get_suspend_value: get the suspend microvoltage value of a given regulator. | |
310 | * | |
311 | * @dev - pointer to the regulator device | |
185f812c | 312 | * Return: - positive output value [uV] on success or negative errno if fail. |
11406b8f JC |
313 | */ |
314 | int regulator_get_suspend_value(struct udevice *dev); | |
315 | ||
2f5d532f K |
316 | /** |
317 | * regulator_set_value_force: set the microvoltage value of a given regulator | |
318 | * without any min-,max condition check | |
319 | * | |
320 | * @dev - pointer to the regulator device | |
321 | * @uV - the output value to set [micro Volts] | |
185f812c | 322 | * Return: - 0 on success or -errno val if fails |
2f5d532f K |
323 | */ |
324 | int regulator_set_value_force(struct udevice *dev, int uV); | |
325 | ||
af41e8db PM |
326 | /** |
327 | * regulator_get_current: get microampere value of a given regulator | |
328 | * | |
329 | * @dev - pointer to the regulator device | |
185f812c | 330 | * Return: - positive output current [uA] on success or negative errno if fail. |
af41e8db PM |
331 | */ |
332 | int regulator_get_current(struct udevice *dev); | |
333 | ||
334 | /** | |
335 | * regulator_set_current: set the microampere value of a given regulator. | |
336 | * | |
337 | * @dev - pointer to the regulator device | |
338 | * @uA - set the output current [micro Amps] | |
185f812c | 339 | * Return: - 0 on success or -errno val if fails |
af41e8db PM |
340 | */ |
341 | int regulator_set_current(struct udevice *dev, int uA); | |
342 | ||
343 | /** | |
344 | * regulator_get_enable: get regulator device enable state. | |
345 | * | |
346 | * @dev - pointer to the regulator device | |
185f812c | 347 | * Return: - true/false of enable state or -errno val if fails |
af41e8db | 348 | */ |
06bdf600 | 349 | int regulator_get_enable(struct udevice *dev); |
af41e8db PM |
350 | |
351 | /** | |
352 | * regulator_set_enable: set regulator enable state | |
353 | * | |
354 | * @dev - pointer to the regulator device | |
355 | * @enable - set true or false | |
185f812c | 356 | * Return: - 0 on success or -errno val if fails |
af41e8db PM |
357 | */ |
358 | int regulator_set_enable(struct udevice *dev, bool enable); | |
359 | ||
cc4a224a LV |
360 | /** |
361 | * regulator_set_enable_if_allowed: set regulator enable state if allowed by | |
362 | * regulator | |
363 | * | |
364 | * @dev - pointer to the regulator device | |
365 | * @enable - set true or false | |
185f812c | 366 | * Return: - 0 on success or if enabling is not supported |
cc4a224a LV |
367 | * -errno val if fails. |
368 | */ | |
369 | int regulator_set_enable_if_allowed(struct udevice *dev, bool enable); | |
370 | ||
11406b8f JC |
371 | /** |
372 | * regulator_set_suspend_enable: set regulator suspend enable state | |
373 | * | |
374 | * @dev - pointer to the regulator device | |
375 | * @enable - set true or false | |
185f812c | 376 | * Return: - 0 on success or -errno val if fails |
11406b8f JC |
377 | */ |
378 | int regulator_set_suspend_enable(struct udevice *dev, bool enable); | |
379 | ||
380 | /** | |
381 | * regulator_get_suspend_enable: get regulator suspend enable state | |
382 | * | |
383 | * @dev - pointer to the regulator device | |
185f812c | 384 | * Return: - true/false of enable state or -errno val if fails |
11406b8f JC |
385 | */ |
386 | int regulator_get_suspend_enable(struct udevice *dev); | |
387 | ||
af41e8db | 388 | /** |
3b880757 | 389 | * regulator_get_mode: get active operation mode id of a given regulator |
af41e8db PM |
390 | * |
391 | * @dev - pointer to the regulator device | |
185f812c | 392 | * Return: - positive mode 'id' number on success or -errno val if fails |
af41e8db | 393 | * Note: |
3b880757 PM |
394 | * The device can provide an array of operating modes, which is type of struct |
395 | * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside | |
396 | * that array. By calling this function, the driver should return an active mode | |
397 | * id of the given regulator device. | |
af41e8db PM |
398 | */ |
399 | int regulator_get_mode(struct udevice *dev); | |
400 | ||
401 | /** | |
3b880757 | 402 | * regulator_set_mode: set the given regulator's, active mode id |
af41e8db | 403 | * |
3b880757 PM |
404 | * @dev - pointer to the regulator device |
405 | * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode) | |
185f812c | 406 | * Return: - 0 on success or -errno value if fails |
af41e8db | 407 | * Note: |
3b880757 PM |
408 | * The device can provide an array of operating modes, which is type of struct |
409 | * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside | |
410 | * that array. By calling this function, the driver should set the active mode | |
411 | * of a given regulator to given by "mode_id" argument. | |
af41e8db | 412 | */ |
3b880757 | 413 | int regulator_set_mode(struct udevice *dev, int mode_id); |
af41e8db | 414 | |
083fc83a SG |
415 | /** |
416 | * regulators_enable_boot_on() - enable regulators needed for boot | |
417 | * | |
418 | * This enables all regulators which are marked to be on at boot time. This | |
419 | * only works for regulators which don't have a range for voltage/current, | |
420 | * since in that case it is not possible to know which value to use. | |
421 | * | |
422 | * This effectively calls regulator_autoset() for every regulator. | |
423 | */ | |
424 | int regulators_enable_boot_on(bool verbose); | |
425 | ||
fec8c900 KP |
426 | /** |
427 | * regulators_enable_boot_off() - disable regulators needed for boot | |
428 | * | |
429 | * This disables all regulators which are marked to be off at boot time. | |
430 | * | |
431 | * This effectively calls regulator_unset() for every regulator. | |
432 | */ | |
433 | int regulators_enable_boot_off(bool verbose); | |
434 | ||
af41e8db | 435 | /** |
3b55d30f SG |
436 | * regulator_autoset: setup the voltage/current on a regulator |
437 | * | |
438 | * The setup depends on constraints found in device's uclass's platform data | |
caa4daa2 | 439 | * (struct dm_regulator_uclass_plat): |
3b55d30f SG |
440 | * |
441 | * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true, | |
442 | * or if both are unset, then the function returns | |
443 | * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal | |
444 | * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal | |
445 | * | |
446 | * The function returns on the first-encountered error. | |
447 | * | |
caa4daa2 | 448 | * @platname - expected string for dm_regulator_uclass_plat .name field |
3b55d30f SG |
449 | * @devp - returned pointer to the regulator device - if non-NULL passed |
450 | * @return: 0 on success or negative value of errno. | |
451 | */ | |
452 | int regulator_autoset(struct udevice *dev); | |
453 | ||
fec8c900 KP |
454 | /** |
455 | * regulator_unset: turn off a regulator | |
456 | * | |
457 | * The setup depends on constraints found in device's uclass's platform data | |
458 | * (struct dm_regulator_uclass_platdata): | |
459 | * | |
460 | * - Disable - will set - if 'force_off' is set to true, | |
461 | * | |
462 | * The function returns on the first-encountered error. | |
463 | */ | |
464 | int regulator_unset(struct udevice *dev); | |
465 | ||
3b55d30f SG |
466 | /** |
467 | * regulator_autoset_by_name: setup the regulator given by its uclass's | |
468 | * platform data name field. The setup depends on constraints found in device's | |
caa4daa2 | 469 | * uclass's platform data (struct dm_regulator_uclass_plat): |
3b880757 PM |
470 | * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true, |
471 | * or if both are unset, then the function returns | |
af41e8db PM |
472 | * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal |
473 | * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal | |
af41e8db PM |
474 | * |
475 | * The function returns on first encountered error. | |
476 | * | |
caa4daa2 | 477 | * @platname - expected string for dm_regulator_uclass_plat .name field |
3b880757 | 478 | * @devp - returned pointer to the regulator device - if non-NULL passed |
1757df46 | 479 | * @return: 0 on success or negative value of errno. |
af41e8db PM |
480 | * |
481 | * The returned 'regulator' device can be used with: | |
482 | * - regulator_get/set_* | |
af41e8db | 483 | */ |
3b55d30f | 484 | int regulator_autoset_by_name(const char *platname, struct udevice **devp); |
af41e8db PM |
485 | |
486 | /** | |
3b880757 PM |
487 | * regulator_list_autoset: setup the regulators given by list of their uclass's |
488 | * platform data name field. The setup depends on constraints found in device's | |
489 | * uclass's platform data. The function loops with calls to: | |
3b55d30f | 490 | * regulator_autoset_by_name() for each name from the list. |
af41e8db PM |
491 | * |
492 | * @list_platname - an array of expected strings for .name field of each | |
caa4daa2 | 493 | * regulator's uclass plat |
af41e8db PM |
494 | * @list_devp - an array of returned pointers to the successfully setup |
495 | * regulator devices if non-NULL passed | |
496 | * @verbose - (true/false) print each regulator setup info, or be quiet | |
185f812c | 497 | * Return: 0 on successfully setup of all list entries, otherwise first error. |
af41e8db PM |
498 | * |
499 | * The returned 'regulator' devices can be used with: | |
500 | * - regulator_get/set_* | |
3b880757 PM |
501 | * |
502 | * Note: The list must ends with NULL entry, like in the "platname" list below: | |
503 | * char *my_regulators[] = { | |
504 | * "VCC_3.3V", | |
505 | * "VCC_1.8V", | |
506 | * NULL, | |
507 | * }; | |
af41e8db | 508 | */ |
3b880757 PM |
509 | int regulator_list_autoset(const char *list_platname[], |
510 | struct udevice *list_devp[], | |
511 | bool verbose); | |
af41e8db PM |
512 | |
513 | /** | |
3b880757 PM |
514 | * regulator_get_by_devname: returns the pointer to the pmic regulator device. |
515 | * Search by name, found in regulator device's name. | |
af41e8db PM |
516 | * |
517 | * @devname - expected string for 'dev->name' of regulator device | |
1757df46 | 518 | * @devp - returned pointer to the regulator device |
185f812c | 519 | * Return: 0 on success or negative value of errno. |
af41e8db | 520 | * |
3b880757 | 521 | * The returned 'regulator' device is probed and can be used with: |
af41e8db PM |
522 | * - regulator_get/set_* |
523 | */ | |
3b880757 | 524 | int regulator_get_by_devname(const char *devname, struct udevice **devp); |
af41e8db PM |
525 | |
526 | /** | |
3b880757 | 527 | * regulator_get_by_platname: returns the pointer to the pmic regulator device. |
caa4daa2 | 528 | * Search by name, found in regulator uclass plat. |
af41e8db | 529 | * |
caa4daa2 | 530 | * @platname - expected string for uc_pdata->name of regulator uclass plat |
3b55d30f | 531 | * @devp - returns pointer to the regulator device or NULL on error |
185f812c | 532 | * Return: 0 on success or negative value of errno. |
af41e8db | 533 | * |
3b880757 | 534 | * The returned 'regulator' device is probed and can be used with: |
af41e8db PM |
535 | * - regulator_get/set_* |
536 | */ | |
3b880757 | 537 | int regulator_get_by_platname(const char *platname, struct udevice **devp); |
af41e8db | 538 | |
7c816e24 PM |
539 | /** |
540 | * device_get_supply_regulator: returns the pointer to the supply regulator. | |
541 | * Search by phandle, found in device's node. | |
542 | * | |
543 | * Note: Please pay attention to proper order of device bind sequence. | |
544 | * The regulator device searched by the phandle, must be binded before | |
545 | * this function call. | |
546 | * | |
547 | * @dev - device with supply phandle | |
548 | * @supply_name - phandle name of regulator | |
549 | * @devp - returned pointer to the supply device | |
185f812c | 550 | * Return: 0 on success or negative value of errno. |
7c816e24 PM |
551 | */ |
552 | int device_get_supply_regulator(struct udevice *dev, const char *supply_name, | |
553 | struct udevice **devp); | |
16cc5ad0 PF |
554 | #else |
555 | static inline int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep) | |
556 | { | |
557 | return -ENOSYS; | |
558 | } | |
559 | ||
560 | static inline int regulator_get_value(struct udevice *dev) | |
561 | { | |
562 | return -ENOSYS; | |
563 | } | |
564 | ||
565 | static inline int regulator_set_value(struct udevice *dev, int uV) | |
566 | { | |
567 | return -ENOSYS; | |
568 | } | |
569 | ||
570 | static inline int regulator_set_suspend_value(struct udevice *dev, int uV) | |
571 | { | |
572 | return -ENOSYS; | |
573 | } | |
574 | ||
575 | static inline int regulator_get_suspend_value(struct udevice *dev) | |
576 | { | |
577 | return -ENOSYS; | |
578 | } | |
579 | ||
580 | static inline int regulator_set_value_force(struct udevice *dev, int uV) | |
581 | { | |
582 | return -ENOSYS; | |
583 | } | |
584 | ||
585 | static inline int regulator_get_current(struct udevice *dev) | |
586 | { | |
587 | return -ENOSYS; | |
588 | } | |
589 | ||
590 | static inline int regulator_set_current(struct udevice *dev, int uA) | |
591 | { | |
592 | return -ENOSYS; | |
593 | } | |
594 | ||
595 | static inline int regulator_get_enable(struct udevice *dev) | |
596 | { | |
597 | return -ENOSYS; | |
598 | } | |
599 | ||
600 | static inline int regulator_set_enable(struct udevice *dev, bool enable) | |
601 | { | |
602 | return -ENOSYS; | |
603 | } | |
604 | ||
605 | static inline int regulator_set_enable_if_allowed(struct udevice *dev, bool enable) | |
606 | { | |
607 | return -ENOSYS; | |
608 | } | |
609 | ||
610 | static inline int regulator_set_suspend_enable(struct udevice *dev, bool enable) | |
611 | { | |
612 | return -ENOSYS; | |
613 | } | |
614 | ||
615 | static inline int regulator_get_suspend_enable(struct udevice *dev) | |
616 | { | |
617 | return -ENOSYS; | |
618 | } | |
619 | ||
620 | static inline int regulator_get_mode(struct udevice *dev) | |
621 | { | |
622 | return -ENOSYS; | |
623 | } | |
624 | ||
625 | static inline int regulator_set_mode(struct udevice *dev, int mode_id) | |
626 | { | |
627 | return -ENOSYS; | |
628 | } | |
629 | ||
630 | static inline int regulators_enable_boot_on(bool verbose) | |
631 | { | |
632 | return -ENOSYS; | |
633 | } | |
634 | ||
635 | static inline int regulator_autoset(struct udevice *dev) | |
636 | { | |
637 | return -ENOSYS; | |
638 | } | |
639 | ||
640 | static inline int regulator_autoset_by_name(const char *platname, struct udevice **devp) | |
641 | { | |
642 | return -ENOSYS; | |
643 | } | |
644 | ||
645 | static inline int regulator_list_autoset(const char *list_platname[], struct udevice *list_devp[], | |
646 | bool verbose) | |
647 | { | |
648 | return -ENOSYS; | |
649 | } | |
650 | ||
651 | static inline int regulator_get_by_devname(const char *devname, struct udevice **devp) | |
652 | { | |
653 | return -ENOSYS; | |
654 | } | |
655 | ||
656 | static inline int regulator_get_by_platname(const char *platname, struct udevice **devp) | |
657 | { | |
658 | return -ENOSYS; | |
659 | } | |
660 | ||
661 | static inline int device_get_supply_regulator(struct udevice *dev, const char *supply_name, | |
662 | struct udevice **devp) | |
663 | { | |
664 | return -ENOSYS; | |
665 | } | |
666 | #endif | |
7c816e24 | 667 | |
af41e8db | 668 | #endif /* _INCLUDE_REGULATOR_H_ */ |