blob: 200652cb3d7a032b55cb2820e4af1400eb40b11a [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,
Jonas Karlmand99fb642023-08-21 22:30:24 +0000137 REGULATOR_FLAG_AUTOSET_DONE = 1 << 2,
Simon Glass7837cea2015-06-23 15:38:57 -0600138};
139
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200140/**
Simon Glasscaa4daa2020-12-03 16:55:18 -0700141 * struct dm_regulator_uclass_plat - pointed by dev->uclass_plat, and
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200142 * allocated on each regulator bind. This structure holds an information
143 * about each regulator's constraints and supported operation modes.
144 * There is no "step" voltage value - so driver should take care of this.
145 *
146 * @type - one of 'enum regulator_type'
147 * @mode - pointer to the regulator mode (array if more than one)
148 * @mode_count - number of '.mode' entries
149 * @min_uV* - minimum voltage (micro Volts)
150 * @max_uV* - maximum voltage (micro Volts)
151 * @min_uA* - minimum amperage (micro Amps)
152 * @max_uA* - maximum amperage (micro Amps)
153 * @always_on* - bool type, true or false
154 * @boot_on* - bool type, true or false
Konstantin Porotchkinfec8c902017-05-29 15:59:38 +0300155 * @force_off* - bool type, true or false
Simon Glass7837cea2015-06-23 15:38:57 -0600156 * TODO(sjg@chromium.org): Consider putting the above two into @flags
Krzysztof Kozlowskie66d1cb2019-03-06 19:37:54 +0100157 * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
Simon Glass7837cea2015-06-23 15:38:57 -0600158 * @flags: - flags value (see REGULATOR_FLAG_...)
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200159 * @name** - fdt regulator name - should be taken from the device tree
Keerthy34514b82016-09-30 09:20:42 +0530160 * ctrl_reg: - Control register offset used to enable/disable regulator
161 * volt_reg: - register offset for writing voltage vsel values
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200162 *
163 * Note:
164 * * - set automatically on device probe by the uclass's '.pre_probe' method.
165 * ** - set automatically on device bind by the uclass's '.post_bind' method.
166 * The constraints: type, mode, mode_count, can be set by device driver, e.g.
167 * by the driver '.probe' method.
168 */
Simon Glasscaa4daa2020-12-03 16:55:18 -0700169struct dm_regulator_uclass_plat {
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200170 enum regulator_type type;
171 struct dm_regulator_mode *mode;
172 int mode_count;
173 int min_uV;
174 int max_uV;
Joseph Chen11406b82019-09-26 15:43:52 +0800175 int init_uV;
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200176 int min_uA;
177 int max_uA;
Krzysztof Kozlowskie66d1cb2019-03-06 19:37:54 +0100178 unsigned int ramp_delay;
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200179 bool always_on;
180 bool boot_on;
Konstantin Porotchkinfec8c902017-05-29 15:59:38 +0300181 bool force_off;
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200182 const char *name;
Simon Glass7837cea2015-06-23 15:38:57 -0600183 int flags;
Keerthy34514b82016-09-30 09:20:42 +0530184 u8 ctrl_reg;
185 u8 volt_reg;
Joseph Chen11406b82019-09-26 15:43:52 +0800186 bool suspend_on;
187 u32 suspend_uV;
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200188};
189
190/* Regulator device operations */
191struct dm_regulator_ops {
192 /**
193 * The regulator output value function calls operates on a micro Volts.
194 *
195 * get/set_value - get/set output value of the given output number
196 * @dev - regulator device
197 * Sets:
198 * @uV - set the output value [micro Volts]
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200199 * @return output value [uV] on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200200 */
201 int (*get_value)(struct udevice *dev);
202 int (*set_value)(struct udevice *dev, int uV);
203
204 /**
Joseph Chen11406b82019-09-26 15:43:52 +0800205 * The regulator suspend output value function calls operates
206 * on a micro Volts.
207 *
208 * get/set_suspen_value - get/set suspend mode output value
209 * @dev - regulator device
210 * Sets:
211 * @uV - set the suspend output value [micro Volts]
212 * @return output value [uV] on success or negative errno if fail.
213 */
214 int (*set_suspend_value)(struct udevice *dev, int uV);
215 int (*get_suspend_value)(struct udevice *dev);
216
217 /**
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200218 * The regulator output current function calls operates on a micro Amps.
219 *
220 * get/set_current - get/set output current of the given output number
221 * @dev - regulator device
222 * Sets:
223 * @uA - set the output current [micro Amps]
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200224 * @return output value [uA] on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200225 */
226 int (*get_current)(struct udevice *dev);
227 int (*set_current)(struct udevice *dev, int uA);
228
229 /**
230 * The most basic feature of the regulator output is its enable state.
231 *
232 * get/set_enable - get/set enable state of the given output number
233 * @dev - regulator device
234 * Sets:
235 * @enable - set true - enable or false - disable
Keerthy06bdf602017-06-13 09:53:45 +0530236 * @return true/false for get or -errno if fail; 0 / -errno for set.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200237 */
Keerthy06bdf602017-06-13 09:53:45 +0530238 int (*get_enable)(struct udevice *dev);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200239 int (*set_enable)(struct udevice *dev, bool enable);
240
241 /**
Joseph Chen11406b82019-09-26 15:43:52 +0800242 * The most basic feature of the regulator output is its enable state
243 * in suspend mode.
244 *
245 * get/set_suspend_enable - get/set enable state of the suspend output
246 * @dev - regulator device
247 * Sets:
248 * @enable - set true - enable or false - disable
249 * @return true/false for get or -errno if fail; 0 / -errno for set.
250 */
251 int (*set_suspend_enable)(struct udevice *dev, bool enable);
252 int (*get_suspend_enable)(struct udevice *dev);
253
254 /**
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200255 * The 'get/set_mode()' function calls should operate on a driver-
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200256 * specific mode id definitions, which should be found in:
257 * field 'id' of struct dm_regulator_mode.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200258 *
259 * get/set_mode - get/set operation mode of the given output number
260 * @dev - regulator device
261 * Sets
262 * @mode_id - set output mode id (struct dm_regulator_mode->id)
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200263 * @return id/0 for get/set on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200264 * Note:
265 * The field 'id' of struct type 'dm_regulator_mode', should be always
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200266 * a positive number, since the negative is reserved for the error.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200267 */
268 int (*get_mode)(struct udevice *dev);
269 int (*set_mode)(struct udevice *dev, int mode_id);
270};
271
Peng Fan16cc5ad2020-10-15 18:06:48 +0800272#if CONFIG_IS_ENABLED(DM_REGULATOR)
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200273/**
274 * regulator_mode: returns a pointer to the array of regulator mode info
275 *
276 * @dev - pointer to the regulator device
277 * @modep - pointer to the returned mode info array
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100278 * Return: - count of modep entries on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200279 */
280int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep);
281
282/**
283 * regulator_get_value: get microvoltage voltage value of a given regulator
284 *
285 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100286 * Return: - positive output value [uV] on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200287 */
288int regulator_get_value(struct udevice *dev);
289
290/**
291 * regulator_set_value: set the microvoltage value of a given regulator.
292 *
293 * @dev - pointer to the regulator device
294 * @uV - the output value to set [micro Volts]
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100295 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200296 */
297int regulator_set_value(struct udevice *dev, int uV);
298
299/**
Joseph Chen11406b82019-09-26 15:43:52 +0800300 * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator.
301 *
302 * @dev - pointer to the regulator device
303 * @uV - the output suspend value to set [micro Volts]
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100304 * Return: - 0 on success or -errno val if fails
Joseph Chen11406b82019-09-26 15:43:52 +0800305 */
306int regulator_set_suspend_value(struct udevice *dev, int uV);
307
308/**
309 * regulator_get_suspend_value: get the suspend microvoltage value of a given regulator.
310 *
311 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100312 * Return: - positive output value [uV] on success or negative errno if fail.
Joseph Chen11406b82019-09-26 15:43:52 +0800313 */
314int regulator_get_suspend_value(struct udevice *dev);
315
316/**
Keerthy2f5d5322016-10-26 13:42:30 +0530317 * regulator_set_value_force: set the microvoltage value of a given regulator
318 * without any min-,max condition check
319 *
320 * @dev - pointer to the regulator device
321 * @uV - the output value to set [micro Volts]
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100322 * Return: - 0 on success or -errno val if fails
Keerthy2f5d5322016-10-26 13:42:30 +0530323 */
324int regulator_set_value_force(struct udevice *dev, int uV);
325
326/**
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200327 * regulator_get_current: get microampere value of a given regulator
328 *
329 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100330 * Return: - positive output current [uA] on success or negative errno if fail.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200331 */
332int regulator_get_current(struct udevice *dev);
333
334/**
335 * regulator_set_current: set the microampere value of a given regulator.
336 *
337 * @dev - pointer to the regulator device
338 * @uA - set the output current [micro Amps]
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100339 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200340 */
341int regulator_set_current(struct udevice *dev, int uA);
342
343/**
344 * regulator_get_enable: get regulator device enable state.
345 *
346 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100347 * Return: - true/false of enable state or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200348 */
Keerthy06bdf602017-06-13 09:53:45 +0530349int regulator_get_enable(struct udevice *dev);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200350
351/**
352 * regulator_set_enable: set regulator enable state
353 *
354 * @dev - pointer to the regulator device
355 * @enable - set true or false
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100356 * Return: - 0 on success or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200357 */
358int regulator_set_enable(struct udevice *dev, bool enable);
359
360/**
Lokesh Vutlacc4a2242019-01-11 15:15:51 +0530361 * regulator_set_enable_if_allowed: set regulator enable state if allowed by
362 * regulator
363 *
364 * @dev - pointer to the regulator device
365 * @enable - set true or false
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100366 * Return: - 0 on success or if enabling is not supported
Lokesh Vutlacc4a2242019-01-11 15:15:51 +0530367 * -errno val if fails.
368 */
369int regulator_set_enable_if_allowed(struct udevice *dev, bool enable);
370
371/**
Joseph Chen11406b82019-09-26 15:43:52 +0800372 * regulator_set_suspend_enable: set regulator suspend enable state
373 *
374 * @dev - pointer to the regulator device
375 * @enable - set true or false
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100376 * Return: - 0 on success or -errno val if fails
Joseph Chen11406b82019-09-26 15:43:52 +0800377 */
378int regulator_set_suspend_enable(struct udevice *dev, bool enable);
379
380/**
381 * regulator_get_suspend_enable: get regulator suspend enable state
382 *
383 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100384 * Return: - true/false of enable state or -errno val if fails
Joseph Chen11406b82019-09-26 15:43:52 +0800385 */
386int regulator_get_suspend_enable(struct udevice *dev);
387
388/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200389 * regulator_get_mode: get active operation mode id of a given regulator
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200390 *
391 * @dev - pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100392 * Return: - positive mode 'id' number on success or -errno val if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200393 * Note:
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200394 * The device can provide an array of operating modes, which is type of struct
395 * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
396 * that array. By calling this function, the driver should return an active mode
397 * id of the given regulator device.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200398 */
399int regulator_get_mode(struct udevice *dev);
400
401/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200402 * regulator_set_mode: set the given regulator's, active mode id
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200403 *
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200404 * @dev - pointer to the regulator device
405 * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100406 * Return: - 0 on success or -errno value if fails
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200407 * Note:
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200408 * The device can provide an array of operating modes, which is type of struct
409 * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
410 * that array. By calling this function, the driver should set the active mode
411 * of a given regulator to given by "mode_id" argument.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200412 */
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200413int regulator_set_mode(struct udevice *dev, int mode_id);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200414
415/**
Simon Glass083fc832015-06-23 15:38:59 -0600416 * regulators_enable_boot_on() - enable regulators needed for boot
417 *
418 * This enables all regulators which are marked to be on at boot time. This
419 * only works for regulators which don't have a range for voltage/current,
420 * since in that case it is not possible to know which value to use.
421 *
422 * This effectively calls regulator_autoset() for every regulator.
423 */
424int regulators_enable_boot_on(bool verbose);
425
426/**
Konstantin Porotchkinfec8c902017-05-29 15:59:38 +0300427 * regulators_enable_boot_off() - disable regulators needed for boot
428 *
429 * This disables all regulators which are marked to be off at boot time.
430 *
431 * This effectively calls regulator_unset() for every regulator.
432 */
433int regulators_enable_boot_off(bool verbose);
434
435/**
Simon Glass3b55d302015-06-23 15:38:58 -0600436 * regulator_autoset: setup the voltage/current on a regulator
437 *
438 * The setup depends on constraints found in device's uclass's platform data
Simon Glasscaa4daa2020-12-03 16:55:18 -0700439 * (struct dm_regulator_uclass_plat):
Simon Glass3b55d302015-06-23 15:38:58 -0600440 *
441 * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
442 * or if both are unset, then the function returns
443 * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
444 * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
445 *
446 * The function returns on the first-encountered error.
447 *
Simon Glasscaa4daa2020-12-03 16:55:18 -0700448 * @platname - expected string for dm_regulator_uclass_plat .name field
Simon Glass3b55d302015-06-23 15:38:58 -0600449 * @devp - returned pointer to the regulator device - if non-NULL passed
450 * @return: 0 on success or negative value of errno.
451 */
452int regulator_autoset(struct udevice *dev);
453
454/**
Konstantin Porotchkinfec8c902017-05-29 15:59:38 +0300455 * regulator_unset: turn off a regulator
456 *
457 * The setup depends on constraints found in device's uclass's platform data
458 * (struct dm_regulator_uclass_platdata):
459 *
460 * - Disable - will set - if 'force_off' is set to true,
461 *
462 * The function returns on the first-encountered error.
463 */
464int regulator_unset(struct udevice *dev);
465
466/**
Simon Glass3b55d302015-06-23 15:38:58 -0600467 * regulator_autoset_by_name: setup the regulator given by its uclass's
468 * platform data name field. The setup depends on constraints found in device's
Simon Glasscaa4daa2020-12-03 16:55:18 -0700469 * uclass's platform data (struct dm_regulator_uclass_plat):
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200470 * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
471 * or if both are unset, then the function returns
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200472 * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
473 * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200474 *
475 * The function returns on first encountered error.
476 *
Simon Glasscaa4daa2020-12-03 16:55:18 -0700477 * @platname - expected string for dm_regulator_uclass_plat .name field
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200478 * @devp - returned pointer to the regulator device - if non-NULL passed
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200479 * @return: 0 on success or negative value of errno.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200480 *
481 * The returned 'regulator' device can be used with:
482 * - regulator_get/set_*
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200483 */
Simon Glass3b55d302015-06-23 15:38:58 -0600484int regulator_autoset_by_name(const char *platname, struct udevice **devp);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200485
486/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200487 * regulator_list_autoset: setup the regulators given by list of their uclass's
488 * platform data name field. The setup depends on constraints found in device's
489 * uclass's platform data. The function loops with calls to:
Simon Glass3b55d302015-06-23 15:38:58 -0600490 * regulator_autoset_by_name() for each name from the list.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200491 *
492 * @list_platname - an array of expected strings for .name field of each
Simon Glasscaa4daa2020-12-03 16:55:18 -0700493 * regulator's uclass plat
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200494 * @list_devp - an array of returned pointers to the successfully setup
495 * regulator devices if non-NULL passed
496 * @verbose - (true/false) print each regulator setup info, or be quiet
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100497 * Return: 0 on successfully setup of all list entries, otherwise first error.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200498 *
499 * The returned 'regulator' devices can be used with:
500 * - regulator_get/set_*
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200501 *
502 * Note: The list must ends with NULL entry, like in the "platname" list below:
503 * char *my_regulators[] = {
504 * "VCC_3.3V",
505 * "VCC_1.8V",
506 * NULL,
507 * };
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200508 */
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200509int regulator_list_autoset(const char *list_platname[],
510 struct udevice *list_devp[],
511 bool verbose);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200512
513/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200514 * regulator_get_by_devname: returns the pointer to the pmic regulator device.
515 * Search by name, found in regulator device's name.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200516 *
517 * @devname - expected string for 'dev->name' of regulator device
Przemyslaw Marczak1757df42015-04-20 20:07:47 +0200518 * @devp - returned pointer to the regulator device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100519 * Return: 0 on success or negative value of errno.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200520 *
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200521 * The returned 'regulator' device is probed and can be used with:
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200522 * - regulator_get/set_*
523 */
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200524int regulator_get_by_devname(const char *devname, struct udevice **devp);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200525
526/**
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200527 * regulator_get_by_platname: returns the pointer to the pmic regulator device.
Simon Glasscaa4daa2020-12-03 16:55:18 -0700528 * Search by name, found in regulator uclass plat.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200529 *
Simon Glasscaa4daa2020-12-03 16:55:18 -0700530 * @platname - expected string for uc_pdata->name of regulator uclass plat
Simon Glass3b55d302015-06-23 15:38:58 -0600531 * @devp - returns pointer to the regulator device or NULL on error
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100532 * Return: 0 on success or negative value of errno.
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200533 *
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200534 * The returned 'regulator' device is probed and can be used with:
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200535 * - regulator_get/set_*
536 */
Przemyslaw Marczak3b880752015-05-13 13:38:27 +0200537int regulator_get_by_platname(const char *platname, struct udevice **devp);
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200538
Przemyslaw Marczak7c816e22015-10-27 13:07:59 +0100539/**
540 * device_get_supply_regulator: returns the pointer to the supply regulator.
541 * Search by phandle, found in device's node.
542 *
543 * Note: Please pay attention to proper order of device bind sequence.
544 * The regulator device searched by the phandle, must be binded before
545 * this function call.
546 *
547 * @dev - device with supply phandle
548 * @supply_name - phandle name of regulator
549 * @devp - returned pointer to the supply device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100550 * Return: 0 on success or negative value of errno.
Przemyslaw Marczak7c816e22015-10-27 13:07:59 +0100551 */
552int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
553 struct udevice **devp);
Peng Fan16cc5ad2020-10-15 18:06:48 +0800554#else
555static inline int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep)
556{
557 return -ENOSYS;
558}
559
560static inline int regulator_get_value(struct udevice *dev)
561{
562 return -ENOSYS;
563}
564
565static inline int regulator_set_value(struct udevice *dev, int uV)
566{
567 return -ENOSYS;
568}
569
570static inline int regulator_set_suspend_value(struct udevice *dev, int uV)
571{
572 return -ENOSYS;
573}
574
575static inline int regulator_get_suspend_value(struct udevice *dev)
576{
577 return -ENOSYS;
578}
579
580static inline int regulator_set_value_force(struct udevice *dev, int uV)
581{
582 return -ENOSYS;
583}
584
585static inline int regulator_get_current(struct udevice *dev)
586{
587 return -ENOSYS;
588}
589
590static inline int regulator_set_current(struct udevice *dev, int uA)
591{
592 return -ENOSYS;
593}
594
595static inline int regulator_get_enable(struct udevice *dev)
596{
597 return -ENOSYS;
598}
599
600static inline int regulator_set_enable(struct udevice *dev, bool enable)
601{
602 return -ENOSYS;
603}
604
605static inline int regulator_set_enable_if_allowed(struct udevice *dev, bool enable)
606{
607 return -ENOSYS;
608}
609
610static inline int regulator_set_suspend_enable(struct udevice *dev, bool enable)
611{
612 return -ENOSYS;
613}
614
615static inline int regulator_get_suspend_enable(struct udevice *dev)
616{
617 return -ENOSYS;
618}
619
620static inline int regulator_get_mode(struct udevice *dev)
621{
622 return -ENOSYS;
623}
624
625static inline int regulator_set_mode(struct udevice *dev, int mode_id)
626{
627 return -ENOSYS;
628}
629
630static inline int regulators_enable_boot_on(bool verbose)
631{
632 return -ENOSYS;
633}
634
635static inline int regulator_autoset(struct udevice *dev)
636{
637 return -ENOSYS;
638}
639
640static inline int regulator_autoset_by_name(const char *platname, struct udevice **devp)
641{
642 return -ENOSYS;
643}
644
645static inline int regulator_list_autoset(const char *list_platname[], struct udevice *list_devp[],
646 bool verbose)
647{
648 return -ENOSYS;
649}
650
651static inline int regulator_get_by_devname(const char *devname, struct udevice **devp)
652{
653 return -ENOSYS;
654}
655
656static inline int regulator_get_by_platname(const char *platname, struct udevice **devp)
657{
658 return -ENOSYS;
659}
660
661static inline int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
662 struct udevice **devp)
663{
664 return -ENOSYS;
665}
666#endif
Przemyslaw Marczak7c816e22015-10-27 13:07:59 +0100667
Przemyslaw Marczakaf41e8d2015-04-20 20:07:42 +0200668#endif /* _INCLUDE_REGULATOR_H_ */