blob: bb07a814c797f11e4240306914569cf5603a205b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Przemyslaw Marczak08edd002015-04-20 20:07:42 +02002/*
3 * Copyright (C) 2014-2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczak08edd002015-04-20 20:07:42 +02005 */
6
7#ifndef _INCLUDE_REGULATOR_H_
8#define _INCLUDE_REGULATOR_H_
9
Max Krummenacher0e226eb2024-01-18 19:10:47 +010010#include <linux/errno.h>
11
Simon Glass3ba929a2020-10-30 21:38:53 -060012struct udevice;
13
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020014/**
15 * U-Boot Voltage/Current Regulator
16 * ================================
17 *
18 * The regulator API is based on a driver model, with the device tree support.
19 * And this header describes the functions and data types for the uclass id:
20 * 'UCLASS_REGULATOR' and the regulator driver API.
21 *
22 * The regulator uclass - is based on uclass platform data which is allocated,
Simon Glass71fa5b42020-12-03 16:55:18 -070023 * automatically for each regulator device on bind and 'dev->uclass_plat'
24 * points to it. The data type is: 'struct dm_regulator_uclass_plat'.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020025 * The uclass file: 'drivers/power/regulator/regulator-uclass.c'
26 *
27 * The regulator device - is based on driver's model 'struct udevice'.
28 * The API can use regulator name in two meanings:
29 * - devname - the regulator device's name: 'dev->name'
Simon Glass71fa5b42020-12-03 16:55:18 -070030 * - platname - the device's plat's name. So in the code it looks like:
31 * 'uc_pdata = dev->uclass_plat'; 'name = uc_pdata->name'.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020032 *
33 * The regulator device driver - provide an implementation of uclass operations
34 * pointed by 'dev->driver->ops' as a struct of type 'struct dm_regulator_ops'.
35 *
36 * To proper bind the regulator device, the device tree node should provide
37 * regulator constraints, like in the example below:
38 *
39 * ldo1 {
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020040 * regulator-name = "VDD_MMC_1.8V"; (must be unique for proper bind)
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020041 * regulator-min-microvolt = <1000000>; (optional)
42 * regulator-max-microvolt = <1000000>; (optional)
43 * regulator-min-microamp = <1000>; (optional)
44 * regulator-max-microamp = <1000>; (optional)
45 * regulator-always-on; (optional)
46 * regulator-boot-on; (optional)
47 * };
48 *
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020049 * Note: For the proper operation, at least name constraint is needed, since
50 * it can be used when calling regulator_get_by_platname(). And the mandatory
51 * rule for this name is, that it must be globally unique for the single dts.
Peng Fanb4cb9ce2015-08-07 16:43:43 +080052 * If regulator-name property is not provided, node name will be chosen.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020053 *
54 * Regulator bind:
Simon Glass6996c662020-11-28 17:50:03 -070055 * For each regulator device, the device_bind() should be called with passed
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020056 * device tree offset. This is required for this uclass's '.post_bind' method,
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020057 * which does the scan on the device node, for the 'regulator-name' constraint.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020058 * If the parent is not a PMIC device, and the child is not bind by function:
59 * 'pmic_bind_childs()', then it's recommended to bind the device by call to
Simon Glass09128c52016-07-05 17:10:09 -060060 * dm_scan_fdt_dev() - this is usually done automatically for bus devices,
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020061 * as a post bind method.
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020062 *
63 * Regulator get:
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020064 * Having the device's name constraint, we can call regulator_by_platname(),
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020065 * to find the required regulator. Before return, the regulator is probed,
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020066 * and the rest of its constraints are put into the device's uclass platform
67 * data, by the uclass regulator '.pre_probe' method.
68 *
69 * For more info about PMIC bind, please refer to file: 'include/power/pmic.h'
70 *
71 * Note:
72 * Please do not use the device_bind_by_name() function, since it pass '-1' as
73 * device node offset - and the bind will fail on uclass .post_bind method,
74 * because of missing 'regulator-name' constraint.
75 *
76 *
77 * Fixed Voltage/Current Regulator
78 * ===============================
79 *
80 * When fixed voltage regulator is needed, then enable the config:
81 * - CONFIG_DM_REGULATOR_FIXED
82 *
83 * The driver file: 'drivers/power/regulator/fixed.c', provides basic support
84 * for control the GPIO, and return the device tree constraint values.
85 *
86 * To bind the fixed voltage regulator device, we usually use a 'simple-bus'
87 * node as a parent. And 'regulator-fixed' for the driver compatible. This is
88 * the same as in the kernel. The example node of fixed regulator:
89 *
90 * simple-bus {
91 * compatible = "simple-bus";
92 * #address-cells = <1>;
93 * #size-cells = <0>;
94 *
95 * blue_led {
96 * compatible = "regulator-fixed";
97 * regulator-name = "VDD_LED_3.3V";
98 * regulator-min-microvolt = <3300000>;
99 * regulator-max-microvolt = <3300000>;
100 * gpio = <&gpc1 0 GPIO_ACTIVE_LOW>;
101 * };
102 * };
103 *
104 * The fixed regulator devices also provide regulator uclass platform data. And
105 * devices bound from such node, can use the regulator drivers API.
106*/
107
108/* enum regulator_type - used for regulator_*() variant calls */
109enum regulator_type {
110 REGULATOR_TYPE_LDO = 0,
111 REGULATOR_TYPE_BUCK,
112 REGULATOR_TYPE_DVS,
113 REGULATOR_TYPE_FIXED,
Keerthy17b3fe72016-09-15 17:04:06 +0530114 REGULATOR_TYPE_GPIO,
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200115 REGULATOR_TYPE_OTHER,
116};
117
118/**
119 * struct dm_regulator_mode - this structure holds an information about
120 * each regulator operation mode. Probably in most cases - an array.
121 * This will be probably a driver-static data, since it is device-specific.
122 *
123 * @id - a driver-specific mode id
124 * @register_value - a driver-specific value for its mode id
125 * @name - the name of mode - used for regulator command
126 * Note:
127 * The field 'id', should be always a positive number, since the negative values
128 * are reserved for the errno numbers when returns the mode id.
129 */
130struct dm_regulator_mode {
131 int id; /* Set only as >= 0 (negative value is reserved for errno) */
132 int register_value;
133 const char *name;
134};
135
Simon Glass991f9bc2015-06-23 15:38:57 -0600136enum regulator_flag {
137 REGULATOR_FLAG_AUTOSET_UV = 1 << 0,
138 REGULATOR_FLAG_AUTOSET_UA = 1 << 1,
Jonas Karlmanc2ef8812023-08-21 22:30:24 +0000139 REGULATOR_FLAG_AUTOSET_DONE = 1 << 2,
Simon Glass991f9bc2015-06-23 15:38:57 -0600140};
141
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200142/**
Simon Glass71fa5b42020-12-03 16:55:18 -0700143 * struct dm_regulator_uclass_plat - pointed by dev->uclass_plat, and
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200144 * allocated on each regulator bind. This structure holds an information
145 * about each regulator's constraints and supported operation modes.
146 * There is no "step" voltage value - so driver should take care of this.
147 *
148 * @type - one of 'enum regulator_type'
149 * @mode - pointer to the regulator mode (array if more than one)
150 * @mode_count - number of '.mode' entries
151 * @min_uV* - minimum voltage (micro Volts)
152 * @max_uV* - maximum voltage (micro Volts)
153 * @min_uA* - minimum amperage (micro Amps)
154 * @max_uA* - maximum amperage (micro Amps)
155 * @always_on* - bool type, true or false
156 * @boot_on* - bool type, true or false
Konstantin Porotchkin621dab52017-05-29 15:59:38 +0300157 * @force_off* - bool type, true or false
Simon Glass991f9bc2015-06-23 15:38:57 -0600158 * TODO(sjg@chromium.org): Consider putting the above two into @flags
Krzysztof Kozlowskie2fa3972019-03-06 19:37:54 +0100159 * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
Simon Glass991f9bc2015-06-23 15:38:57 -0600160 * @flags: - flags value (see REGULATOR_FLAG_...)
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200161 * @name** - fdt regulator name - should be taken from the device tree
Keerthy4d96cd02016-09-30 09:20:42 +0530162 * ctrl_reg: - Control register offset used to enable/disable regulator
163 * volt_reg: - register offset for writing voltage vsel values
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200164 *
165 * Note:
166 * * - set automatically on device probe by the uclass's '.pre_probe' method.
167 * ** - set automatically on device bind by the uclass's '.post_bind' method.
168 * The constraints: type, mode, mode_count, can be set by device driver, e.g.
169 * by the driver '.probe' method.
170 */
Simon Glass71fa5b42020-12-03 16:55:18 -0700171struct dm_regulator_uclass_plat {
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200172 enum regulator_type type;
173 struct dm_regulator_mode *mode;
174 int mode_count;
175 int min_uV;
176 int max_uV;
Joseph Chenbb511322019-09-26 15:43:52 +0800177 int init_uV;
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200178 int min_uA;
179 int max_uA;
Krzysztof Kozlowskie2fa3972019-03-06 19:37:54 +0100180 unsigned int ramp_delay;
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200181 bool always_on;
182 bool boot_on;
Konstantin Porotchkin621dab52017-05-29 15:59:38 +0300183 bool force_off;
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200184 const char *name;
Simon Glass991f9bc2015-06-23 15:38:57 -0600185 int flags;
Keerthy4d96cd02016-09-30 09:20:42 +0530186 u8 ctrl_reg;
187 u8 volt_reg;
Joseph Chenbb511322019-09-26 15:43:52 +0800188 bool suspend_on;
189 u32 suspend_uV;
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200190};
191
192/* Regulator device operations */
193struct dm_regulator_ops {
194 /**
195 * The regulator output value function calls operates on a micro Volts.
196 *
197 * get/set_value - get/set output value of the given output number
198 * @dev - regulator device
199 * Sets:
200 * @uV - set the output value [micro Volts]
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200201 * @return output value [uV] on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200202 */
203 int (*get_value)(struct udevice *dev);
204 int (*set_value)(struct udevice *dev, int uV);
205
206 /**
Joseph Chenbb511322019-09-26 15:43:52 +0800207 * The regulator suspend output value function calls operates
208 * on a micro Volts.
209 *
210 * get/set_suspen_value - get/set suspend mode output value
211 * @dev - regulator device
212 * Sets:
213 * @uV - set the suspend output value [micro Volts]
214 * @return output value [uV] on success or negative errno if fail.
215 */
216 int (*set_suspend_value)(struct udevice *dev, int uV);
217 int (*get_suspend_value)(struct udevice *dev);
218
219 /**
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200220 * The regulator output current function calls operates on a micro Amps.
221 *
222 * get/set_current - get/set output current of the given output number
223 * @dev - regulator device
224 * Sets:
225 * @uA - set the output current [micro Amps]
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200226 * @return output value [uA] on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200227 */
228 int (*get_current)(struct udevice *dev);
229 int (*set_current)(struct udevice *dev, int uA);
230
231 /**
232 * The most basic feature of the regulator output is its enable state.
233 *
234 * get/set_enable - get/set enable state of the given output number
235 * @dev - regulator device
236 * Sets:
237 * @enable - set true - enable or false - disable
Keerthy23be7fb2017-06-13 09:53:45 +0530238 * @return true/false for get or -errno if fail; 0 / -errno for set.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200239 */
Keerthy23be7fb2017-06-13 09:53:45 +0530240 int (*get_enable)(struct udevice *dev);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200241 int (*set_enable)(struct udevice *dev, bool enable);
242
243 /**
Joseph Chenbb511322019-09-26 15:43:52 +0800244 * The most basic feature of the regulator output is its enable state
245 * in suspend mode.
246 *
247 * get/set_suspend_enable - get/set enable state of the suspend output
248 * @dev - regulator device
249 * Sets:
250 * @enable - set true - enable or false - disable
251 * @return true/false for get or -errno if fail; 0 / -errno for set.
252 */
253 int (*set_suspend_enable)(struct udevice *dev, bool enable);
254 int (*get_suspend_enable)(struct udevice *dev);
255
256 /**
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200257 * The 'get/set_mode()' function calls should operate on a driver-
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200258 * specific mode id definitions, which should be found in:
259 * field 'id' of struct dm_regulator_mode.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200260 *
261 * get/set_mode - get/set operation mode of the given output number
262 * @dev - regulator device
263 * Sets
264 * @mode_id - set output mode id (struct dm_regulator_mode->id)
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200265 * @return id/0 for get/set on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200266 * Note:
267 * The field 'id' of struct type 'dm_regulator_mode', should be always
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200268 * a positive number, since the negative is reserved for the error.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200269 */
270 int (*get_mode)(struct udevice *dev);
271 int (*set_mode)(struct udevice *dev, int mode_id);
272};
273
Peng Fana1a2a222020-10-15 18:06:48 +0800274#if CONFIG_IS_ENABLED(DM_REGULATOR)
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200275/**
276 * regulator_mode: returns a pointer to the array of regulator mode info
277 *
278 * @dev - pointer to the regulator device
279 * @modep - pointer to the returned mode info array
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100280 * Return: - count of modep entries on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200281 */
282int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep);
283
284/**
285 * regulator_get_value: get microvoltage voltage value of a given regulator
286 *
287 * @dev - pointer to the regulator device
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100288 * Return: - positive output value [uV] on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200289 */
290int regulator_get_value(struct udevice *dev);
291
292/**
293 * regulator_set_value: set the microvoltage value of a given regulator.
294 *
295 * @dev - pointer to the regulator device
296 * @uV - the output value to set [micro Volts]
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100297 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200298 */
299int regulator_set_value(struct udevice *dev, int uV);
300
301/**
Joseph Chenbb511322019-09-26 15:43:52 +0800302 * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator.
303 *
304 * @dev - pointer to the regulator device
305 * @uV - the output suspend value to set [micro Volts]
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100306 * Return: - 0 on success or -errno val if fails
Joseph Chenbb511322019-09-26 15:43:52 +0800307 */
308int regulator_set_suspend_value(struct udevice *dev, int uV);
309
310/**
311 * regulator_get_suspend_value: get the suspend microvoltage value of a given regulator.
312 *
313 * @dev - pointer to the regulator device
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100314 * Return: - positive output value [uV] on success or negative errno if fail.
Joseph Chenbb511322019-09-26 15:43:52 +0800315 */
316int regulator_get_suspend_value(struct udevice *dev);
317
318/**
Keerthy162c02e2016-10-26 13:42:30 +0530319 * regulator_set_value_force: set the microvoltage value of a given regulator
320 * without any min-,max condition check
321 *
322 * @dev - pointer to the regulator device
323 * @uV - the output value to set [micro Volts]
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100324 * Return: - 0 on success or -errno val if fails
Keerthy162c02e2016-10-26 13:42:30 +0530325 */
326int regulator_set_value_force(struct udevice *dev, int uV);
327
328/**
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200329 * regulator_get_current: get microampere value of a given regulator
330 *
331 * @dev - pointer to the regulator device
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100332 * Return: - positive output current [uA] on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200333 */
334int regulator_get_current(struct udevice *dev);
335
336/**
337 * regulator_set_current: set the microampere value of a given regulator.
338 *
339 * @dev - pointer to the regulator device
340 * @uA - set the output current [micro Amps]
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100341 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200342 */
343int regulator_set_current(struct udevice *dev, int uA);
344
345/**
346 * regulator_get_enable: get regulator device enable state.
347 *
348 * @dev - pointer to the regulator device
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100349 * Return: - true/false of enable state or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200350 */
Keerthy23be7fb2017-06-13 09:53:45 +0530351int regulator_get_enable(struct udevice *dev);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200352
353/**
354 * regulator_set_enable: set regulator enable state
355 *
356 * @dev - pointer to the regulator device
357 * @enable - set true or false
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100358 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200359 */
360int regulator_set_enable(struct udevice *dev, bool enable);
361
362/**
Lokesh Vutla7106b782019-01-11 15:15:51 +0530363 * regulator_set_enable_if_allowed: set regulator enable state if allowed by
364 * regulator
365 *
366 * @dev - pointer to the regulator device
367 * @enable - set true or false
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100368 * Return: - 0 on success or if enabling is not supported
Lokesh Vutla7106b782019-01-11 15:15:51 +0530369 * -errno val if fails.
370 */
371int regulator_set_enable_if_allowed(struct udevice *dev, bool enable);
372
373/**
Joseph Chenbb511322019-09-26 15:43:52 +0800374 * regulator_set_suspend_enable: set regulator suspend enable state
375 *
376 * @dev - pointer to the regulator device
377 * @enable - set true or false
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100378 * Return: - 0 on success or -errno val if fails
Joseph Chenbb511322019-09-26 15:43:52 +0800379 */
380int regulator_set_suspend_enable(struct udevice *dev, bool enable);
381
382/**
383 * regulator_get_suspend_enable: get regulator suspend enable state
384 *
385 * @dev - pointer to the regulator device
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100386 * Return: - true/false of enable state or -errno val if fails
Joseph Chenbb511322019-09-26 15:43:52 +0800387 */
388int regulator_get_suspend_enable(struct udevice *dev);
389
390/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200391 * regulator_get_mode: get active operation mode id of a given regulator
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200392 *
393 * @dev - pointer to the regulator device
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100394 * Return: - positive mode 'id' number on success or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200395 * Note:
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200396 * The device can provide an array of operating modes, which is type of struct
397 * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
398 * that array. By calling this function, the driver should return an active mode
399 * id of the given regulator device.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200400 */
401int regulator_get_mode(struct udevice *dev);
402
403/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200404 * regulator_set_mode: set the given regulator's, active mode id
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200405 *
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200406 * @dev - pointer to the regulator device
407 * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100408 * Return: - 0 on success or -errno value if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200409 * Note:
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200410 * The device can provide an array of operating modes, which is type of struct
411 * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
412 * that array. By calling this function, the driver should set the active mode
413 * of a given regulator to given by "mode_id" argument.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200414 */
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200415int regulator_set_mode(struct udevice *dev, int mode_id);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200416
417/**
Simon Glassefeeb2c2015-06-23 15:38:59 -0600418 * regulators_enable_boot_on() - enable regulators needed for boot
419 *
420 * This enables all regulators which are marked to be on at boot time. This
421 * only works for regulators which don't have a range for voltage/current,
422 * since in that case it is not possible to know which value to use.
423 *
424 * This effectively calls regulator_autoset() for every regulator.
425 */
426int regulators_enable_boot_on(bool verbose);
427
428/**
Konstantin Porotchkin621dab52017-05-29 15:59:38 +0300429 * regulators_enable_boot_off() - disable regulators needed for boot
430 *
431 * This disables all regulators which are marked to be off at boot time.
432 *
433 * This effectively calls regulator_unset() for every regulator.
434 */
435int regulators_enable_boot_off(bool verbose);
436
437/**
Simon Glass46cb8242015-06-23 15:38:58 -0600438 * regulator_autoset: setup the voltage/current on a regulator
439 *
440 * The setup depends on constraints found in device's uclass's platform data
Simon Glass71fa5b42020-12-03 16:55:18 -0700441 * (struct dm_regulator_uclass_plat):
Simon Glass46cb8242015-06-23 15:38:58 -0600442 *
443 * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
444 * or if both are unset, then the function returns
445 * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
446 * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
447 *
448 * The function returns on the first-encountered error.
449 *
Simon Glass71fa5b42020-12-03 16:55:18 -0700450 * @platname - expected string for dm_regulator_uclass_plat .name field
Simon Glass46cb8242015-06-23 15:38:58 -0600451 * @devp - returned pointer to the regulator device - if non-NULL passed
452 * @return: 0 on success or negative value of errno.
453 */
454int regulator_autoset(struct udevice *dev);
455
456/**
Konstantin Porotchkin621dab52017-05-29 15:59:38 +0300457 * regulator_unset: turn off a regulator
458 *
459 * The setup depends on constraints found in device's uclass's platform data
460 * (struct dm_regulator_uclass_platdata):
461 *
462 * - Disable - will set - if 'force_off' is set to true,
463 *
464 * The function returns on the first-encountered error.
465 */
466int regulator_unset(struct udevice *dev);
467
468/**
Simon Glass46cb8242015-06-23 15:38:58 -0600469 * regulator_autoset_by_name: setup the regulator given by its uclass's
470 * platform data name field. The setup depends on constraints found in device's
Simon Glass71fa5b42020-12-03 16:55:18 -0700471 * uclass's platform data (struct dm_regulator_uclass_plat):
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200472 * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
473 * or if both are unset, then the function returns
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200474 * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
475 * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200476 *
477 * The function returns on first encountered error.
478 *
Simon Glass71fa5b42020-12-03 16:55:18 -0700479 * @platname - expected string for dm_regulator_uclass_plat .name field
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200480 * @devp - returned pointer to the regulator device - if non-NULL passed
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200481 * @return: 0 on success or negative value of errno.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200482 *
483 * The returned 'regulator' device can be used with:
484 * - regulator_get/set_*
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200485 */
Simon Glass46cb8242015-06-23 15:38:58 -0600486int regulator_autoset_by_name(const char *platname, struct udevice **devp);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200487
488/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200489 * regulator_list_autoset: setup the regulators given by list of their uclass's
490 * platform data name field. The setup depends on constraints found in device's
491 * uclass's platform data. The function loops with calls to:
Simon Glass46cb8242015-06-23 15:38:58 -0600492 * regulator_autoset_by_name() for each name from the list.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200493 *
494 * @list_platname - an array of expected strings for .name field of each
Simon Glass71fa5b42020-12-03 16:55:18 -0700495 * regulator's uclass plat
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200496 * @list_devp - an array of returned pointers to the successfully setup
497 * regulator devices if non-NULL passed
498 * @verbose - (true/false) print each regulator setup info, or be quiet
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100499 * Return: 0 on successfully setup of all list entries, otherwise first error.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200500 *
501 * The returned 'regulator' devices can be used with:
502 * - regulator_get/set_*
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200503 *
504 * Note: The list must ends with NULL entry, like in the "platname" list below:
505 * char *my_regulators[] = {
506 * "VCC_3.3V",
507 * "VCC_1.8V",
508 * NULL,
509 * };
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200510 */
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200511int regulator_list_autoset(const char *list_platname[],
512 struct udevice *list_devp[],
513 bool verbose);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200514
515/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200516 * regulator_get_by_devname: returns the pointer to the pmic regulator device.
517 * Search by name, found in regulator device's name.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200518 *
519 * @devname - expected string for 'dev->name' of regulator device
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200520 * @devp - returned pointer to the regulator device
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100521 * Return: 0 on success or negative value of errno.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200522 *
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200523 * The returned 'regulator' device is probed and can be used with:
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200524 * - regulator_get/set_*
525 */
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200526int regulator_get_by_devname(const char *devname, struct udevice **devp);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200527
528/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200529 * regulator_get_by_platname: returns the pointer to the pmic regulator device.
Simon Glass71fa5b42020-12-03 16:55:18 -0700530 * Search by name, found in regulator uclass plat.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200531 *
Simon Glass71fa5b42020-12-03 16:55:18 -0700532 * @platname - expected string for uc_pdata->name of regulator uclass plat
Simon Glass46cb8242015-06-23 15:38:58 -0600533 * @devp - returns pointer to the regulator device or NULL on error
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100534 * Return: 0 on success or negative value of errno.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200535 *
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200536 * The returned 'regulator' device is probed and can be used with:
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200537 * - regulator_get/set_*
538 */
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200539int regulator_get_by_platname(const char *platname, struct udevice **devp);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200540
Przemyslaw Marczakc9001032015-10-27 13:07:59 +0100541/**
542 * device_get_supply_regulator: returns the pointer to the supply regulator.
543 * Search by phandle, found in device's node.
544 *
545 * Note: Please pay attention to proper order of device bind sequence.
546 * The regulator device searched by the phandle, must be binded before
547 * this function call.
548 *
549 * @dev - device with supply phandle
550 * @supply_name - phandle name of regulator
551 * @devp - returned pointer to the supply device
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100552 * Return: 0 on success or negative value of errno.
Przemyslaw Marczakc9001032015-10-27 13:07:59 +0100553 */
554int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
555 struct udevice **devp);
Peng Fana1a2a222020-10-15 18:06:48 +0800556#else
557static inline int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep)
558{
559 return -ENOSYS;
560}
561
562static inline int regulator_get_value(struct udevice *dev)
563{
564 return -ENOSYS;
565}
566
567static inline int regulator_set_value(struct udevice *dev, int uV)
568{
569 return -ENOSYS;
570}
571
572static inline int regulator_set_suspend_value(struct udevice *dev, int uV)
573{
574 return -ENOSYS;
575}
576
577static inline int regulator_get_suspend_value(struct udevice *dev)
578{
579 return -ENOSYS;
580}
581
582static inline int regulator_set_value_force(struct udevice *dev, int uV)
583{
584 return -ENOSYS;
585}
586
587static inline int regulator_get_current(struct udevice *dev)
588{
589 return -ENOSYS;
590}
591
592static inline int regulator_set_current(struct udevice *dev, int uA)
593{
594 return -ENOSYS;
595}
596
597static inline int regulator_get_enable(struct udevice *dev)
598{
599 return -ENOSYS;
600}
601
602static inline int regulator_set_enable(struct udevice *dev, bool enable)
603{
604 return -ENOSYS;
605}
606
607static inline int regulator_set_enable_if_allowed(struct udevice *dev, bool enable)
608{
609 return -ENOSYS;
610}
611
612static inline int regulator_set_suspend_enable(struct udevice *dev, bool enable)
613{
614 return -ENOSYS;
615}
616
617static inline int regulator_get_suspend_enable(struct udevice *dev)
618{
619 return -ENOSYS;
620}
621
622static inline int regulator_get_mode(struct udevice *dev)
623{
624 return -ENOSYS;
625}
626
627static inline int regulator_set_mode(struct udevice *dev, int mode_id)
628{
629 return -ENOSYS;
630}
631
632static inline int regulators_enable_boot_on(bool verbose)
633{
634 return -ENOSYS;
635}
636
637static inline int regulator_autoset(struct udevice *dev)
638{
639 return -ENOSYS;
640}
641
642static inline int regulator_autoset_by_name(const char *platname, struct udevice **devp)
643{
644 return -ENOSYS;
645}
646
647static inline int regulator_list_autoset(const char *list_platname[], struct udevice *list_devp[],
648 bool verbose)
649{
650 return -ENOSYS;
651}
652
653static inline int regulator_get_by_devname(const char *devname, struct udevice **devp)
654{
655 return -ENOSYS;
656}
657
658static inline int regulator_get_by_platname(const char *platname, struct udevice **devp)
659{
660 return -ENOSYS;
661}
662
663static inline int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
664 struct udevice **devp)
665{
666 return -ENOSYS;
667}
668#endif
Przemyslaw Marczakc9001032015-10-27 13:07:59 +0100669
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200670#endif /* _INCLUDE_REGULATOR_H_ */