blob: ff1bfc2435aef0069576986cacc463624b77833f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +02002/*
3 * Copyright (C) 2014-2015 Samsung Electronics
4 * Przemyslaw Marczak <p.marczak@samsung.com>
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +02005 */
6
7#ifndef _INCLUDE_REGULATOR_H_
8#define _INCLUDE_REGULATOR_H_
9
Simon Glass401d1c42020-10-30 21:38:53 -060010struct udevice;
11
Przemyslaw Marczakaf41e8d2015-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 Glasscaa4daa2020-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 Marczakaf41e8d2015-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 Glasscaa4daa2020-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 Marczakaf41e8d2015-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 Marczak3b880752015-05-13 13:38:27 +020038 * regulator-name = "VDD_MMC_1.8V"; (must be unique for proper bind)
Przemyslaw Marczakaf41e8d2015-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 Marczak3b880752015-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 Fan40ade2c2015-08-07 16:43:43 +080050 * If regulator-name property is not provided, node name will be chosen.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +020051 *
52 * Regulator bind:
Simon Glassa2703ce2020-11-28 17:50:03 -070053 * For each regulator device, the device_bind() should be called with passed
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +020054 * device tree offset. This is required for this uclass's '.post_bind' method,
Przemyslaw Marczak3b880752015-05-13 13:38:27 +020055 * which does the scan on the device node, for the 'regulator-name' constraint.
Przemyslaw Marczakaf41e8d2015-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 Glass2e3f1ff2016-07-05 17:10:09 -060058 * dm_scan_fdt_dev() - this is usually done automatically for bus devices,
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +020059 * as a post bind method.
Przemyslaw Marczak3b880752015-05-13 13:38:27 +020060 *
61 * Regulator get:
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +020062 * Having the device's name constraint, we can call regulator_by_platname(),
Przemyslaw Marczak3b880752015-05-13 13:38:27 +020063 * to find the required regulator. Before return, the regulator is probed,
Przemyslaw Marczakaf41e8d2015-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,
Keerthy477dfe22016-09-15 17:04:06 +0530112 REGULATOR_TYPE_GPIO,
Przemyslaw Marczakaf41e8d2015-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 Glass7837cea2015-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 Marczakaf41e8d2015-04-20 20:07:42 +0200139/**
Simon Glasscaa4daa2020-12-03 16:55:18 -0700140 * struct dm_regulator_uclass_plat - pointed by dev->uclass_plat, and
Przemyslaw Marczakaf41e8d2015-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
Konstantin Porotchkinfec8c902017-05-29 15:59:38 +0300154 * @force_off* - bool type, true or false
Simon Glass7837cea2015-06-23 15:38:57 -0600155 * TODO(sjg@chromium.org): Consider putting the above two into @flags
Krzysztof Kozlowskie66d1cb2019-03-06 19:37:54 +0100156 * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
Simon Glass7837cea2015-06-23 15:38:57 -0600157 * @flags: - flags value (see REGULATOR_FLAG_...)
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200158 * @name** - fdt regulator name - should be taken from the device tree
Keerthy34514b82016-09-30 09:20:42 +0530159 * ctrl_reg: - Control register offset used to enable/disable regulator
160 * volt_reg: - register offset for writing voltage vsel values
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200161 *
162 * Note:
163 * * - set automatically on device probe by the uclass's '.pre_probe' method.
164 * ** - set automatically on device bind by the uclass's '.post_bind' method.
165 * The constraints: type, mode, mode_count, can be set by device driver, e.g.
166 * by the driver '.probe' method.
167 */
Simon Glasscaa4daa2020-12-03 16:55:18 -0700168struct dm_regulator_uclass_plat {
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200169 enum regulator_type type;
170 struct dm_regulator_mode *mode;
171 int mode_count;
172 int min_uV;
173 int max_uV;
Joseph Chen11406b82019-09-26 15:43:52 +0800174 int init_uV;
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200175 int min_uA;
176 int max_uA;
Krzysztof Kozlowskie66d1cb2019-03-06 19:37:54 +0100177 unsigned int ramp_delay;
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200178 bool always_on;
179 bool boot_on;
Konstantin Porotchkinfec8c902017-05-29 15:59:38 +0300180 bool force_off;
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200181 const char *name;
Simon Glass7837cea2015-06-23 15:38:57 -0600182 int flags;
Keerthy34514b82016-09-30 09:20:42 +0530183 u8 ctrl_reg;
184 u8 volt_reg;
Joseph Chen11406b82019-09-26 15:43:52 +0800185 bool suspend_on;
186 u32 suspend_uV;
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200187};
188
189/* Regulator device operations */
190struct dm_regulator_ops {
191 /**
192 * The regulator output value function calls operates on a micro Volts.
193 *
194 * get/set_value - get/set output value of the given output number
195 * @dev - regulator device
196 * Sets:
197 * @uV - set the output value [micro Volts]
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200198 * @return output value [uV] on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200199 */
200 int (*get_value)(struct udevice *dev);
201 int (*set_value)(struct udevice *dev, int uV);
202
203 /**
Joseph Chen11406b82019-09-26 15:43:52 +0800204 * The regulator suspend output value function calls operates
205 * on a micro Volts.
206 *
207 * get/set_suspen_value - get/set suspend mode output value
208 * @dev - regulator device
209 * Sets:
210 * @uV - set the suspend output value [micro Volts]
211 * @return output value [uV] on success or negative errno if fail.
212 */
213 int (*set_suspend_value)(struct udevice *dev, int uV);
214 int (*get_suspend_value)(struct udevice *dev);
215
216 /**
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200217 * The regulator output current function calls operates on a micro Amps.
218 *
219 * get/set_current - get/set output current of the given output number
220 * @dev - regulator device
221 * Sets:
222 * @uA - set the output current [micro Amps]
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200223 * @return output value [uA] on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200224 */
225 int (*get_current)(struct udevice *dev);
226 int (*set_current)(struct udevice *dev, int uA);
227
228 /**
229 * The most basic feature of the regulator output is its enable state.
230 *
231 * get/set_enable - get/set enable state of the given output number
232 * @dev - regulator device
233 * Sets:
234 * @enable - set true - enable or false - disable
Keerthy06bdf602017-06-13 09:53:45 +0530235 * @return true/false for get or -errno if fail; 0 / -errno for set.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200236 */
Keerthy06bdf602017-06-13 09:53:45 +0530237 int (*get_enable)(struct udevice *dev);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200238 int (*set_enable)(struct udevice *dev, bool enable);
239
240 /**
Joseph Chen11406b82019-09-26 15:43:52 +0800241 * The most basic feature of the regulator output is its enable state
242 * in suspend mode.
243 *
244 * get/set_suspend_enable - get/set enable state of the suspend output
245 * @dev - regulator device
246 * Sets:
247 * @enable - set true - enable or false - disable
248 * @return true/false for get or -errno if fail; 0 / -errno for set.
249 */
250 int (*set_suspend_enable)(struct udevice *dev, bool enable);
251 int (*get_suspend_enable)(struct udevice *dev);
252
253 /**
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200254 * The 'get/set_mode()' function calls should operate on a driver-
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200255 * specific mode id definitions, which should be found in:
256 * field 'id' of struct dm_regulator_mode.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200257 *
258 * get/set_mode - get/set operation mode of the given output number
259 * @dev - regulator device
260 * Sets
261 * @mode_id - set output mode id (struct dm_regulator_mode->id)
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200262 * @return id/0 for get/set on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200263 * Note:
264 * The field 'id' of struct type 'dm_regulator_mode', should be always
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200265 * a positive number, since the negative is reserved for the error.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200266 */
267 int (*get_mode)(struct udevice *dev);
268 int (*set_mode)(struct udevice *dev, int mode_id);
269};
270
Peng Fan16cc5ad2020-10-15 18:06:48 +0800271#if CONFIG_IS_ENABLED(DM_REGULATOR)
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200272/**
273 * regulator_mode: returns a pointer to the array of regulator mode info
274 *
275 * @dev - pointer to the regulator device
276 * @modep - pointer to the returned mode info array
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100277 * Return: - count of modep entries on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200278 */
279int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep);
280
281/**
282 * regulator_get_value: get microvoltage voltage value of a given regulator
283 *
284 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100285 * Return: - positive output value [uV] on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200286 */
287int regulator_get_value(struct udevice *dev);
288
289/**
290 * regulator_set_value: set the microvoltage value of a given regulator.
291 *
292 * @dev - pointer to the regulator device
293 * @uV - the output value to set [micro Volts]
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100294 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200295 */
296int regulator_set_value(struct udevice *dev, int uV);
297
298/**
Joseph Chen11406b82019-09-26 15:43:52 +0800299 * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator.
300 *
301 * @dev - pointer to the regulator device
302 * @uV - the output suspend value to set [micro Volts]
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100303 * Return: - 0 on success or -errno val if fails
Joseph Chen11406b82019-09-26 15:43:52 +0800304 */
305int regulator_set_suspend_value(struct udevice *dev, int uV);
306
307/**
308 * regulator_get_suspend_value: get the suspend microvoltage value of a given regulator.
309 *
310 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100311 * Return: - positive output value [uV] on success or negative errno if fail.
Joseph Chen11406b82019-09-26 15:43:52 +0800312 */
313int regulator_get_suspend_value(struct udevice *dev);
314
315/**
Keerthy2f5d5322016-10-26 13:42:30 +0530316 * regulator_set_value_force: set the microvoltage value of a given regulator
317 * without any min-,max condition check
318 *
319 * @dev - pointer to the regulator device
320 * @uV - the output value to set [micro Volts]
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100321 * Return: - 0 on success or -errno val if fails
Keerthy2f5d5322016-10-26 13:42:30 +0530322 */
323int regulator_set_value_force(struct udevice *dev, int uV);
324
325/**
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200326 * regulator_get_current: get microampere value of a given regulator
327 *
328 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100329 * Return: - positive output current [uA] on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200330 */
331int regulator_get_current(struct udevice *dev);
332
333/**
334 * regulator_set_current: set the microampere value of a given regulator.
335 *
336 * @dev - pointer to the regulator device
337 * @uA - set the output current [micro Amps]
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100338 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200339 */
340int regulator_set_current(struct udevice *dev, int uA);
341
342/**
343 * regulator_get_enable: get regulator device enable state.
344 *
345 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100346 * Return: - true/false of enable state or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200347 */
Keerthy06bdf602017-06-13 09:53:45 +0530348int regulator_get_enable(struct udevice *dev);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200349
350/**
351 * regulator_set_enable: set regulator enable state
352 *
353 * @dev - pointer to the regulator device
354 * @enable - set true or false
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100355 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200356 */
357int regulator_set_enable(struct udevice *dev, bool enable);
358
359/**
Lokesh Vutlacc4a2242019-01-11 15:15:51 +0530360 * regulator_set_enable_if_allowed: set regulator enable state if allowed by
361 * regulator
362 *
363 * @dev - pointer to the regulator device
364 * @enable - set true or false
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100365 * Return: - 0 on success or if enabling is not supported
Lokesh Vutlacc4a2242019-01-11 15:15:51 +0530366 * -errno val if fails.
367 */
368int regulator_set_enable_if_allowed(struct udevice *dev, bool enable);
369
370/**
Joseph Chen11406b82019-09-26 15:43:52 +0800371 * regulator_set_suspend_enable: set regulator suspend enable state
372 *
373 * @dev - pointer to the regulator device
374 * @enable - set true or false
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100375 * Return: - 0 on success or -errno val if fails
Joseph Chen11406b82019-09-26 15:43:52 +0800376 */
377int regulator_set_suspend_enable(struct udevice *dev, bool enable);
378
379/**
380 * regulator_get_suspend_enable: get regulator suspend enable state
381 *
382 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100383 * Return: - true/false of enable state or -errno val if fails
Joseph Chen11406b82019-09-26 15:43:52 +0800384 */
385int regulator_get_suspend_enable(struct udevice *dev);
386
387/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200388 * regulator_get_mode: get active operation mode id of a given regulator
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200389 *
390 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100391 * Return: - positive mode 'id' number on success or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200392 * Note:
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200393 * The device can provide an array of operating modes, which is type of struct
394 * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
395 * that array. By calling this function, the driver should return an active mode
396 * id of the given regulator device.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200397 */
398int regulator_get_mode(struct udevice *dev);
399
400/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200401 * regulator_set_mode: set the given regulator's, active mode id
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200402 *
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200403 * @dev - pointer to the regulator device
404 * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100405 * Return: - 0 on success or -errno value if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200406 * Note:
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200407 * The device can provide an array of operating modes, which is type of struct
408 * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
409 * that array. By calling this function, the driver should set the active mode
410 * of a given regulator to given by "mode_id" argument.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200411 */
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200412int regulator_set_mode(struct udevice *dev, int mode_id);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200413
414/**
Simon Glass083fc832015-06-23 15:38:59 -0600415 * regulators_enable_boot_on() - enable regulators needed for boot
416 *
417 * This enables all regulators which are marked to be on at boot time. This
418 * only works for regulators which don't have a range for voltage/current,
419 * since in that case it is not possible to know which value to use.
420 *
421 * This effectively calls regulator_autoset() for every regulator.
422 */
423int regulators_enable_boot_on(bool verbose);
424
425/**
Konstantin Porotchkinfec8c902017-05-29 15:59:38 +0300426 * regulators_enable_boot_off() - disable regulators needed for boot
427 *
428 * This disables all regulators which are marked to be off at boot time.
429 *
430 * This effectively calls regulator_unset() for every regulator.
431 */
432int regulators_enable_boot_off(bool verbose);
433
434/**
Simon Glass3b55d302015-06-23 15:38:58 -0600435 * regulator_autoset: setup the voltage/current on a regulator
436 *
437 * The setup depends on constraints found in device's uclass's platform data
Simon Glasscaa4daa2020-12-03 16:55:18 -0700438 * (struct dm_regulator_uclass_plat):
Simon Glass3b55d302015-06-23 15:38:58 -0600439 *
440 * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
441 * or if both are unset, then the function returns
442 * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
443 * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
444 *
445 * The function returns on the first-encountered error.
446 *
Simon Glasscaa4daa2020-12-03 16:55:18 -0700447 * @platname - expected string for dm_regulator_uclass_plat .name field
Simon Glass3b55d302015-06-23 15:38:58 -0600448 * @devp - returned pointer to the regulator device - if non-NULL passed
449 * @return: 0 on success or negative value of errno.
450 */
451int regulator_autoset(struct udevice *dev);
452
453/**
Konstantin Porotchkinfec8c902017-05-29 15:59:38 +0300454 * regulator_unset: turn off a regulator
455 *
456 * The setup depends on constraints found in device's uclass's platform data
457 * (struct dm_regulator_uclass_platdata):
458 *
459 * - Disable - will set - if 'force_off' is set to true,
460 *
461 * The function returns on the first-encountered error.
462 */
463int regulator_unset(struct udevice *dev);
464
465/**
Simon Glass3b55d302015-06-23 15:38:58 -0600466 * regulator_autoset_by_name: setup the regulator given by its uclass's
467 * platform data name field. The setup depends on constraints found in device's
Simon Glasscaa4daa2020-12-03 16:55:18 -0700468 * uclass's platform data (struct dm_regulator_uclass_plat):
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200469 * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
470 * or if both are unset, then the function returns
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200471 * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
472 * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200473 *
474 * The function returns on first encountered error.
475 *
Simon Glasscaa4daa2020-12-03 16:55:18 -0700476 * @platname - expected string for dm_regulator_uclass_plat .name field
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200477 * @devp - returned pointer to the regulator device - if non-NULL passed
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200478 * @return: 0 on success or negative value of errno.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200479 *
480 * The returned 'regulator' device can be used with:
481 * - regulator_get/set_*
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200482 */
Simon Glass3b55d302015-06-23 15:38:58 -0600483int regulator_autoset_by_name(const char *platname, struct udevice **devp);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200484
485/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200486 * regulator_list_autoset: setup the regulators given by list of their uclass's
487 * platform data name field. The setup depends on constraints found in device's
488 * uclass's platform data. The function loops with calls to:
Simon Glass3b55d302015-06-23 15:38:58 -0600489 * regulator_autoset_by_name() for each name from the list.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200490 *
491 * @list_platname - an array of expected strings for .name field of each
Simon Glasscaa4daa2020-12-03 16:55:18 -0700492 * regulator's uclass plat
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200493 * @list_devp - an array of returned pointers to the successfully setup
494 * regulator devices if non-NULL passed
495 * @verbose - (true/false) print each regulator setup info, or be quiet
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100496 * Return: 0 on successfully setup of all list entries, otherwise first error.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200497 *
498 * The returned 'regulator' devices can be used with:
499 * - regulator_get/set_*
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200500 *
501 * Note: The list must ends with NULL entry, like in the "platname" list below:
502 * char *my_regulators[] = {
503 * "VCC_3.3V",
504 * "VCC_1.8V",
505 * NULL,
506 * };
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200507 */
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200508int regulator_list_autoset(const char *list_platname[],
509 struct udevice *list_devp[],
510 bool verbose);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200511
512/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200513 * regulator_get_by_devname: returns the pointer to the pmic regulator device.
514 * Search by name, found in regulator device's name.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200515 *
516 * @devname - expected string for 'dev->name' of regulator device
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200517 * @devp - returned pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100518 * Return: 0 on success or negative value of errno.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200519 *
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200520 * The returned 'regulator' device is probed and can be used with:
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200521 * - regulator_get/set_*
522 */
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200523int regulator_get_by_devname(const char *devname, struct udevice **devp);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200524
525/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200526 * regulator_get_by_platname: returns the pointer to the pmic regulator device.
Simon Glasscaa4daa2020-12-03 16:55:18 -0700527 * Search by name, found in regulator uclass plat.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200528 *
Simon Glasscaa4daa2020-12-03 16:55:18 -0700529 * @platname - expected string for uc_pdata->name of regulator uclass plat
Simon Glass3b55d302015-06-23 15:38:58 -0600530 * @devp - returns pointer to the regulator device or NULL on error
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100531 * Return: 0 on success or negative value of errno.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200532 *
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200533 * The returned 'regulator' device is probed and can be used with:
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200534 * - regulator_get/set_*
535 */
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200536int regulator_get_by_platname(const char *platname, struct udevice **devp);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200537
Przemyslaw Marczak7c816e22015-10-27 13:07:59 +0100538/**
539 * device_get_supply_regulator: returns the pointer to the supply regulator.
540 * Search by phandle, found in device's node.
541 *
542 * Note: Please pay attention to proper order of device bind sequence.
543 * The regulator device searched by the phandle, must be binded before
544 * this function call.
545 *
546 * @dev - device with supply phandle
547 * @supply_name - phandle name of regulator
548 * @devp - returned pointer to the supply device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100549 * Return: 0 on success or negative value of errno.
Przemyslaw Marczak7c816e22015-10-27 13:07:59 +0100550 */
551int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
552 struct udevice **devp);
Peng Fan16cc5ad2020-10-15 18:06:48 +0800553#else
554static inline int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep)
555{
556 return -ENOSYS;
557}
558
559static inline int regulator_get_value(struct udevice *dev)
560{
561 return -ENOSYS;
562}
563
564static inline int regulator_set_value(struct udevice *dev, int uV)
565{
566 return -ENOSYS;
567}
568
569static inline int regulator_set_suspend_value(struct udevice *dev, int uV)
570{
571 return -ENOSYS;
572}
573
574static inline int regulator_get_suspend_value(struct udevice *dev)
575{
576 return -ENOSYS;
577}
578
579static inline int regulator_set_value_force(struct udevice *dev, int uV)
580{
581 return -ENOSYS;
582}
583
584static inline int regulator_get_current(struct udevice *dev)
585{
586 return -ENOSYS;
587}
588
589static inline int regulator_set_current(struct udevice *dev, int uA)
590{
591 return -ENOSYS;
592}
593
594static inline int regulator_get_enable(struct udevice *dev)
595{
596 return -ENOSYS;
597}
598
599static inline int regulator_set_enable(struct udevice *dev, bool enable)
600{
601 return -ENOSYS;
602}
603
604static inline int regulator_set_enable_if_allowed(struct udevice *dev, bool enable)
605{
606 return -ENOSYS;
607}
608
609static inline int regulator_set_suspend_enable(struct udevice *dev, bool enable)
610{
611 return -ENOSYS;
612}
613
614static inline int regulator_get_suspend_enable(struct udevice *dev)
615{
616 return -ENOSYS;
617}
618
619static inline int regulator_get_mode(struct udevice *dev)
620{
621 return -ENOSYS;
622}
623
624static inline int regulator_set_mode(struct udevice *dev, int mode_id)
625{
626 return -ENOSYS;
627}
628
629static inline int regulators_enable_boot_on(bool verbose)
630{
631 return -ENOSYS;
632}
633
634static inline int regulator_autoset(struct udevice *dev)
635{
636 return -ENOSYS;
637}
638
639static inline int regulator_autoset_by_name(const char *platname, struct udevice **devp)
640{
641 return -ENOSYS;
642}
643
644static inline int regulator_list_autoset(const char *list_platname[], struct udevice *list_devp[],
645 bool verbose)
646{
647 return -ENOSYS;
648}
649
650static inline int regulator_get_by_devname(const char *devname, struct udevice **devp)
651{
652 return -ENOSYS;
653}
654
655static inline int regulator_get_by_platname(const char *platname, struct udevice **devp)
656{
657 return -ENOSYS;
658}
659
660static inline int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
661 struct udevice **devp)
662{
663 return -ENOSYS;
664}
665#endif
Przemyslaw Marczak7c816e22015-10-27 13:07:59 +0100666
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200667#endif /* _INCLUDE_REGULATOR_H_ */