blob: da9a065bdde0b61149681f1835db9cec544e9d17 [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
Simon Glass3ba929a2020-10-30 21:38:53 -060010struct udevice;
11
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020012/**
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,
Simon Glass71fa5b42020-12-03 16:55:18 -070021 * automatically for each regulator device on bind and 'dev->uclass_plat'
22 * points to it. The data type is: 'struct dm_regulator_uclass_plat'.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020023 * 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'
Simon Glass71fa5b42020-12-03 16:55:18 -070028 * - platname - the device's plat's name. So in the code it looks like:
29 * 'uc_pdata = dev->uclass_plat'; 'name = uc_pdata->name'.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020030 *
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 {
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020038 * regulator-name = "VDD_MMC_1.8V"; (must be unique for proper bind)
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020039 * 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 *
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020047 * 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.
Peng Fanb4cb9ce2015-08-07 16:43:43 +080050 * If regulator-name property is not provided, node name will be chosen.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020051 *
52 * Regulator bind:
Simon Glass6996c662020-11-28 17:50:03 -070053 * For each regulator device, the device_bind() should be called with passed
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020054 * device tree offset. This is required for this uclass's '.post_bind' method,
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020055 * which does the scan on the device node, for the 'regulator-name' constraint.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020056 * 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
Simon Glass09128c52016-07-05 17:10:09 -060058 * dm_scan_fdt_dev() - this is usually done automatically for bus devices,
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020059 * as a post bind method.
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020060 *
61 * Regulator get:
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020062 * Having the device's name constraint, we can call regulator_by_platname(),
Przemyslaw Marczak75692a32015-05-13 13:38:27 +020063 * to find the required regulator. Before return, the regulator is probed,
Przemyslaw Marczak08edd002015-04-20 20:07:42 +020064 * 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 */
107enum regulator_type {
108 REGULATOR_TYPE_LDO = 0,
109 REGULATOR_TYPE_BUCK,
110 REGULATOR_TYPE_DVS,
111 REGULATOR_TYPE_FIXED,
Keerthy17b3fe72016-09-15 17:04:06 +0530112 REGULATOR_TYPE_GPIO,
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200113 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 */
128struct 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
Simon Glass991f9bc2015-06-23 15:38:57 -0600134enum regulator_flag {
135 REGULATOR_FLAG_AUTOSET_UV = 1 << 0,
136 REGULATOR_FLAG_AUTOSET_UA = 1 << 1,
137};
138
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200139/**
Simon Glass71fa5b42020-12-03 16:55:18 -0700140 * struct dm_regulator_uclass_plat - pointed by dev->uclass_plat, and
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200141 * allocated on each regulator bind. This structure holds an information
142 * about each regulator's constraints and supported operation modes.
143 * There is no "step" voltage value - so driver should take care of this.
144 *
145 * @type - one of 'enum regulator_type'
146 * @mode - pointer to the regulator mode (array if more than one)
147 * @mode_count - number of '.mode' entries
148 * @min_uV* - minimum voltage (micro Volts)
149 * @max_uV* - maximum voltage (micro Volts)
150 * @min_uA* - minimum amperage (micro Amps)
151 * @max_uA* - maximum amperage (micro Amps)
152 * @always_on* - bool type, true or false
153 * @boot_on* - bool type, true or false
Simon Glass991f9bc2015-06-23 15:38:57 -0600154 * TODO(sjg@chromium.org): Consider putting the above two into @flags
Krzysztof Kozlowskie2fa3972019-03-06 19:37:54 +0100155 * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
Simon Glass991f9bc2015-06-23 15:38:57 -0600156 * @flags: - flags value (see REGULATOR_FLAG_...)
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200157 * @name** - fdt regulator name - should be taken from the device tree
Keerthy4d96cd02016-09-30 09:20:42 +0530158 * ctrl_reg: - Control register offset used to enable/disable regulator
159 * volt_reg: - register offset for writing voltage vsel values
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200160 *
161 * Note:
162 * * - set automatically on device probe by the uclass's '.pre_probe' method.
163 * ** - set automatically on device bind by the uclass's '.post_bind' method.
164 * The constraints: type, mode, mode_count, can be set by device driver, e.g.
165 * by the driver '.probe' method.
166 */
Simon Glass71fa5b42020-12-03 16:55:18 -0700167struct dm_regulator_uclass_plat {
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200168 enum regulator_type type;
169 struct dm_regulator_mode *mode;
170 int mode_count;
171 int min_uV;
172 int max_uV;
Joseph Chenbb511322019-09-26 15:43:52 +0800173 int init_uV;
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200174 int min_uA;
175 int max_uA;
Krzysztof Kozlowskie2fa3972019-03-06 19:37:54 +0100176 unsigned int ramp_delay;
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200177 bool always_on;
178 bool boot_on;
179 const char *name;
Simon Glass991f9bc2015-06-23 15:38:57 -0600180 int flags;
Keerthy4d96cd02016-09-30 09:20:42 +0530181 u8 ctrl_reg;
182 u8 volt_reg;
Joseph Chenbb511322019-09-26 15:43:52 +0800183 bool suspend_on;
184 u32 suspend_uV;
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200185};
186
187/* Regulator device operations */
188struct dm_regulator_ops {
189 /**
190 * The regulator output value function calls operates on a micro Volts.
191 *
192 * get/set_value - get/set output value of the given output number
193 * @dev - regulator device
194 * Sets:
195 * @uV - set the output value [micro Volts]
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200196 * @return output value [uV] on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200197 */
198 int (*get_value)(struct udevice *dev);
199 int (*set_value)(struct udevice *dev, int uV);
200
201 /**
Joseph Chenbb511322019-09-26 15:43:52 +0800202 * The regulator suspend output value function calls operates
203 * on a micro Volts.
204 *
205 * get/set_suspen_value - get/set suspend mode output value
206 * @dev - regulator device
207 * Sets:
208 * @uV - set the suspend output value [micro Volts]
209 * @return output value [uV] on success or negative errno if fail.
210 */
211 int (*set_suspend_value)(struct udevice *dev, int uV);
212 int (*get_suspend_value)(struct udevice *dev);
213
214 /**
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200215 * The regulator output current function calls operates on a micro Amps.
216 *
217 * get/set_current - get/set output current of the given output number
218 * @dev - regulator device
219 * Sets:
220 * @uA - set the output current [micro Amps]
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200221 * @return output value [uA] on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200222 */
223 int (*get_current)(struct udevice *dev);
224 int (*set_current)(struct udevice *dev, int uA);
225
226 /**
227 * The most basic feature of the regulator output is its enable state.
228 *
229 * get/set_enable - get/set enable state of the given output number
230 * @dev - regulator device
231 * Sets:
232 * @enable - set true - enable or false - disable
Keerthy23be7fb2017-06-13 09:53:45 +0530233 * @return true/false for get or -errno if fail; 0 / -errno for set.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200234 */
Keerthy23be7fb2017-06-13 09:53:45 +0530235 int (*get_enable)(struct udevice *dev);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200236 int (*set_enable)(struct udevice *dev, bool enable);
237
238 /**
Joseph Chenbb511322019-09-26 15:43:52 +0800239 * The most basic feature of the regulator output is its enable state
240 * in suspend mode.
241 *
242 * get/set_suspend_enable - get/set enable state of the suspend output
243 * @dev - regulator device
244 * Sets:
245 * @enable - set true - enable or false - disable
246 * @return true/false for get or -errno if fail; 0 / -errno for set.
247 */
248 int (*set_suspend_enable)(struct udevice *dev, bool enable);
249 int (*get_suspend_enable)(struct udevice *dev);
250
251 /**
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200252 * The 'get/set_mode()' function calls should operate on a driver-
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200253 * specific mode id definitions, which should be found in:
254 * field 'id' of struct dm_regulator_mode.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200255 *
256 * get/set_mode - get/set operation mode of the given output number
257 * @dev - regulator device
258 * Sets
259 * @mode_id - set output mode id (struct dm_regulator_mode->id)
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200260 * @return id/0 for get/set on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200261 * Note:
262 * The field 'id' of struct type 'dm_regulator_mode', should be always
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200263 * a positive number, since the negative is reserved for the error.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200264 */
265 int (*get_mode)(struct udevice *dev);
266 int (*set_mode)(struct udevice *dev, int mode_id);
267};
268
Peng Fana1a2a222020-10-15 18:06:48 +0800269#if CONFIG_IS_ENABLED(DM_REGULATOR)
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200270/**
271 * regulator_mode: returns a pointer to the array of regulator mode info
272 *
273 * @dev - pointer to the regulator device
274 * @modep - pointer to the returned mode info array
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200275 * @return - count of modep entries on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200276 */
277int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep);
278
279/**
280 * regulator_get_value: get microvoltage voltage value of a given regulator
281 *
282 * @dev - pointer to the regulator device
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200283 * @return - positive output value [uV] on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200284 */
285int regulator_get_value(struct udevice *dev);
286
287/**
288 * regulator_set_value: set the microvoltage value of a given regulator.
289 *
290 * @dev - pointer to the regulator device
291 * @uV - the output value to set [micro Volts]
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200292 * @return - 0 on success or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200293 */
294int regulator_set_value(struct udevice *dev, int uV);
295
296/**
Joseph Chenbb511322019-09-26 15:43:52 +0800297 * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator.
298 *
299 * @dev - pointer to the regulator device
300 * @uV - the output suspend value to set [micro Volts]
301 * @return - 0 on success or -errno val if fails
302 */
303int regulator_set_suspend_value(struct udevice *dev, int uV);
304
305/**
306 * regulator_get_suspend_value: get the suspend microvoltage value of a given regulator.
307 *
308 * @dev - pointer to the regulator device
309 * @return - positive output value [uV] on success or negative errno if fail.
310 */
311int regulator_get_suspend_value(struct udevice *dev);
312
313/**
Keerthy162c02e2016-10-26 13:42:30 +0530314 * regulator_set_value_force: set the microvoltage value of a given regulator
315 * without any min-,max condition check
316 *
317 * @dev - pointer to the regulator device
318 * @uV - the output value to set [micro Volts]
319 * @return - 0 on success or -errno val if fails
320 */
321int regulator_set_value_force(struct udevice *dev, int uV);
322
323/**
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200324 * regulator_get_current: get microampere value of a given regulator
325 *
326 * @dev - pointer to the regulator device
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200327 * @return - positive output current [uA] on success or negative errno if fail.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200328 */
329int regulator_get_current(struct udevice *dev);
330
331/**
332 * regulator_set_current: set the microampere value of a given regulator.
333 *
334 * @dev - pointer to the regulator device
335 * @uA - set the output current [micro Amps]
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200336 * @return - 0 on success or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200337 */
338int regulator_set_current(struct udevice *dev, int uA);
339
340/**
341 * regulator_get_enable: get regulator device enable state.
342 *
343 * @dev - pointer to the regulator device
Keerthy23be7fb2017-06-13 09:53:45 +0530344 * @return - true/false of enable state or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200345 */
Keerthy23be7fb2017-06-13 09:53:45 +0530346int regulator_get_enable(struct udevice *dev);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200347
348/**
349 * regulator_set_enable: set regulator enable state
350 *
351 * @dev - pointer to the regulator device
352 * @enable - set true or false
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200353 * @return - 0 on success or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200354 */
355int regulator_set_enable(struct udevice *dev, bool enable);
356
357/**
Lokesh Vutla7106b782019-01-11 15:15:51 +0530358 * regulator_set_enable_if_allowed: set regulator enable state if allowed by
359 * regulator
360 *
361 * @dev - pointer to the regulator device
362 * @enable - set true or false
363 * @return - 0 on success or if enabling is not supported
364 * -errno val if fails.
365 */
366int regulator_set_enable_if_allowed(struct udevice *dev, bool enable);
367
368/**
Joseph Chenbb511322019-09-26 15:43:52 +0800369 * regulator_set_suspend_enable: set regulator suspend enable state
370 *
371 * @dev - pointer to the regulator device
372 * @enable - set true or false
373 * @return - 0 on success or -errno val if fails
374 */
375int regulator_set_suspend_enable(struct udevice *dev, bool enable);
376
377/**
378 * regulator_get_suspend_enable: get regulator suspend enable state
379 *
380 * @dev - pointer to the regulator device
381 * @return - true/false of enable state or -errno val if fails
382 */
383int regulator_get_suspend_enable(struct udevice *dev);
384
385/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200386 * regulator_get_mode: get active operation mode id of a given regulator
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200387 *
388 * @dev - pointer to the regulator device
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200389 * @return - positive mode 'id' number on success or -errno val if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200390 * Note:
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200391 * The device can provide an array of operating modes, which is type of struct
392 * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
393 * that array. By calling this function, the driver should return an active mode
394 * id of the given regulator device.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200395 */
396int regulator_get_mode(struct udevice *dev);
397
398/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200399 * regulator_set_mode: set the given regulator's, active mode id
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200400 *
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200401 * @dev - pointer to the regulator device
402 * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode)
403 * @return - 0 on success or -errno value if fails
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200404 * Note:
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200405 * The device can provide an array of operating modes, which is type of struct
406 * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
407 * that array. By calling this function, the driver should set the active mode
408 * of a given regulator to given by "mode_id" argument.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200409 */
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200410int regulator_set_mode(struct udevice *dev, int mode_id);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200411
412/**
Simon Glassefeeb2c2015-06-23 15:38:59 -0600413 * regulators_enable_boot_on() - enable regulators needed for boot
414 *
415 * This enables all regulators which are marked to be on at boot time. This
416 * only works for regulators which don't have a range for voltage/current,
417 * since in that case it is not possible to know which value to use.
418 *
419 * This effectively calls regulator_autoset() for every regulator.
420 */
421int regulators_enable_boot_on(bool verbose);
422
423/**
Simon Glass46cb8242015-06-23 15:38:58 -0600424 * regulator_autoset: setup the voltage/current on a regulator
425 *
426 * The setup depends on constraints found in device's uclass's platform data
Simon Glass71fa5b42020-12-03 16:55:18 -0700427 * (struct dm_regulator_uclass_plat):
Simon Glass46cb8242015-06-23 15:38:58 -0600428 *
429 * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
430 * or if both are unset, then the function returns
431 * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
432 * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
433 *
434 * The function returns on the first-encountered error.
435 *
Simon Glass71fa5b42020-12-03 16:55:18 -0700436 * @platname - expected string for dm_regulator_uclass_plat .name field
Simon Glass46cb8242015-06-23 15:38:58 -0600437 * @devp - returned pointer to the regulator device - if non-NULL passed
438 * @return: 0 on success or negative value of errno.
439 */
440int regulator_autoset(struct udevice *dev);
441
442/**
443 * regulator_autoset_by_name: setup the regulator given by its uclass's
444 * platform data name field. The setup depends on constraints found in device's
Simon Glass71fa5b42020-12-03 16:55:18 -0700445 * uclass's platform data (struct dm_regulator_uclass_plat):
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200446 * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
447 * or if both are unset, then the function returns
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200448 * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
449 * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200450 *
451 * The function returns on first encountered error.
452 *
Simon Glass71fa5b42020-12-03 16:55:18 -0700453 * @platname - expected string for dm_regulator_uclass_plat .name field
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200454 * @devp - returned pointer to the regulator device - if non-NULL passed
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200455 * @return: 0 on success or negative value of errno.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200456 *
457 * The returned 'regulator' device can be used with:
458 * - regulator_get/set_*
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200459 */
Simon Glass46cb8242015-06-23 15:38:58 -0600460int regulator_autoset_by_name(const char *platname, struct udevice **devp);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200461
462/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200463 * regulator_list_autoset: setup the regulators given by list of their uclass's
464 * platform data name field. The setup depends on constraints found in device's
465 * uclass's platform data. The function loops with calls to:
Simon Glass46cb8242015-06-23 15:38:58 -0600466 * regulator_autoset_by_name() for each name from the list.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200467 *
468 * @list_platname - an array of expected strings for .name field of each
Simon Glass71fa5b42020-12-03 16:55:18 -0700469 * regulator's uclass plat
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200470 * @list_devp - an array of returned pointers to the successfully setup
471 * regulator devices if non-NULL passed
472 * @verbose - (true/false) print each regulator setup info, or be quiet
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200473 * @return 0 on successfully setup of all list entries, otherwise first error.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200474 *
475 * The returned 'regulator' devices can be used with:
476 * - regulator_get/set_*
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200477 *
478 * Note: The list must ends with NULL entry, like in the "platname" list below:
479 * char *my_regulators[] = {
480 * "VCC_3.3V",
481 * "VCC_1.8V",
482 * NULL,
483 * };
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200484 */
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200485int regulator_list_autoset(const char *list_platname[],
486 struct udevice *list_devp[],
487 bool verbose);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200488
489/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200490 * regulator_get_by_devname: returns the pointer to the pmic regulator device.
491 * Search by name, found in regulator device's name.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200492 *
493 * @devname - expected string for 'dev->name' of regulator device
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200494 * @devp - returned pointer to the regulator device
495 * @return 0 on success or negative value of errno.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200496 *
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200497 * The returned 'regulator' device is probed and can be used with:
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200498 * - regulator_get/set_*
499 */
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200500int regulator_get_by_devname(const char *devname, struct udevice **devp);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200501
502/**
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200503 * regulator_get_by_platname: returns the pointer to the pmic regulator device.
Simon Glass71fa5b42020-12-03 16:55:18 -0700504 * Search by name, found in regulator uclass plat.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200505 *
Simon Glass71fa5b42020-12-03 16:55:18 -0700506 * @platname - expected string for uc_pdata->name of regulator uclass plat
Simon Glass46cb8242015-06-23 15:38:58 -0600507 * @devp - returns pointer to the regulator device or NULL on error
Przemyslaw Marczakafee81e2015-04-20 20:07:47 +0200508 * @return 0 on success or negative value of errno.
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200509 *
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200510 * The returned 'regulator' device is probed and can be used with:
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200511 * - regulator_get/set_*
512 */
Przemyslaw Marczak75692a32015-05-13 13:38:27 +0200513int regulator_get_by_platname(const char *platname, struct udevice **devp);
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200514
Przemyslaw Marczakc9001032015-10-27 13:07:59 +0100515/**
516 * device_get_supply_regulator: returns the pointer to the supply regulator.
517 * Search by phandle, found in device's node.
518 *
519 * Note: Please pay attention to proper order of device bind sequence.
520 * The regulator device searched by the phandle, must be binded before
521 * this function call.
522 *
523 * @dev - device with supply phandle
524 * @supply_name - phandle name of regulator
525 * @devp - returned pointer to the supply device
526 * @return 0 on success or negative value of errno.
527 */
528int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
529 struct udevice **devp);
Peng Fana1a2a222020-10-15 18:06:48 +0800530#else
531static inline int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep)
532{
533 return -ENOSYS;
534}
535
536static inline int regulator_get_value(struct udevice *dev)
537{
538 return -ENOSYS;
539}
540
541static inline int regulator_set_value(struct udevice *dev, int uV)
542{
543 return -ENOSYS;
544}
545
546static inline int regulator_set_suspend_value(struct udevice *dev, int uV)
547{
548 return -ENOSYS;
549}
550
551static inline int regulator_get_suspend_value(struct udevice *dev)
552{
553 return -ENOSYS;
554}
555
556static inline int regulator_set_value_force(struct udevice *dev, int uV)
557{
558 return -ENOSYS;
559}
560
561static inline int regulator_get_current(struct udevice *dev)
562{
563 return -ENOSYS;
564}
565
566static inline int regulator_set_current(struct udevice *dev, int uA)
567{
568 return -ENOSYS;
569}
570
571static inline int regulator_get_enable(struct udevice *dev)
572{
573 return -ENOSYS;
574}
575
576static inline int regulator_set_enable(struct udevice *dev, bool enable)
577{
578 return -ENOSYS;
579}
580
581static inline int regulator_set_enable_if_allowed(struct udevice *dev, bool enable)
582{
583 return -ENOSYS;
584}
585
586static inline int regulator_set_suspend_enable(struct udevice *dev, bool enable)
587{
588 return -ENOSYS;
589}
590
591static inline int regulator_get_suspend_enable(struct udevice *dev)
592{
593 return -ENOSYS;
594}
595
596static inline int regulator_get_mode(struct udevice *dev)
597{
598 return -ENOSYS;
599}
600
601static inline int regulator_set_mode(struct udevice *dev, int mode_id)
602{
603 return -ENOSYS;
604}
605
606static inline int regulators_enable_boot_on(bool verbose)
607{
608 return -ENOSYS;
609}
610
611static inline int regulator_autoset(struct udevice *dev)
612{
613 return -ENOSYS;
614}
615
616static inline int regulator_autoset_by_name(const char *platname, struct udevice **devp)
617{
618 return -ENOSYS;
619}
620
621static inline int regulator_list_autoset(const char *list_platname[], struct udevice *list_devp[],
622 bool verbose)
623{
624 return -ENOSYS;
625}
626
627static inline int regulator_get_by_devname(const char *devname, struct udevice **devp)
628{
629 return -ENOSYS;
630}
631
632static inline int regulator_get_by_platname(const char *platname, struct udevice **devp)
633{
634 return -ENOSYS;
635}
636
637static inline int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
638 struct udevice **devp)
639{
640 return -ENOSYS;
641}
642#endif
Przemyslaw Marczakc9001032015-10-27 13:07:59 +0100643
Przemyslaw Marczak08edd002015-04-20 20:07:42 +0200644#endif /* _INCLUDE_REGULATOR_H_ */