xref: /OK3568_Linux_fs/u-boot/include/power/regulator.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  Copyright (C) 2014-2015 Samsung Electronics
3*4882a593Smuzhiyun  *  Przemyslaw Marczak <p.marczak@samsung.com>
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef _INCLUDE_REGULATOR_H_
9*4882a593Smuzhiyun #define _INCLUDE_REGULATOR_H_
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /**
12*4882a593Smuzhiyun  * U-Boot Voltage/Current Regulator
13*4882a593Smuzhiyun  * ================================
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * The regulator API is based on a driver model, with the device tree support.
16*4882a593Smuzhiyun  * And this header describes the functions and data types for the uclass id:
17*4882a593Smuzhiyun  * 'UCLASS_REGULATOR' and the regulator driver API.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * The regulator uclass - is based on uclass platform data which is allocated,
20*4882a593Smuzhiyun  * automatically for each regulator device on bind and 'dev->uclass_platdata'
21*4882a593Smuzhiyun  * points to it. The data type is: 'struct dm_regulator_uclass_platdata'.
22*4882a593Smuzhiyun  * The uclass file: 'drivers/power/regulator/regulator-uclass.c'
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * The regulator device - is based on driver's model 'struct udevice'.
25*4882a593Smuzhiyun  * The API can use regulator name in two meanings:
26*4882a593Smuzhiyun  * - devname  - the regulator device's name: 'dev->name'
27*4882a593Smuzhiyun  * - platname - the device's platdata's name. So in the code it looks like:
28*4882a593Smuzhiyun  *              'uc_pdata = dev->uclass_platdata'; 'name = uc_pdata->name'.
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * The regulator device driver - provide an implementation of uclass operations
31*4882a593Smuzhiyun  * pointed by 'dev->driver->ops' as a struct of type 'struct dm_regulator_ops'.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * To proper bind the regulator device, the device tree node should provide
34*4882a593Smuzhiyun  * regulator constraints, like in the example below:
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * ldo1 {
37*4882a593Smuzhiyun  *      regulator-name = "VDD_MMC_1.8V";     (must be unique for proper bind)
38*4882a593Smuzhiyun  *      regulator-min-microvolt = <1000000>; (optional)
39*4882a593Smuzhiyun  *      regulator-max-microvolt = <1000000>; (optional)
40*4882a593Smuzhiyun  *      regulator-min-microamp = <1000>;     (optional)
41*4882a593Smuzhiyun  *      regulator-max-microamp = <1000>;     (optional)
42*4882a593Smuzhiyun  *      regulator-always-on;                 (optional)
43*4882a593Smuzhiyun  *      regulator-boot-on;                   (optional)
44*4882a593Smuzhiyun  * };
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  * Note: For the proper operation, at least name constraint is needed, since
47*4882a593Smuzhiyun  * it can be used when calling regulator_get_by_platname(). And the mandatory
48*4882a593Smuzhiyun  * rule for this name is, that it must be globally unique for the single dts.
49*4882a593Smuzhiyun  * If regulator-name property is not provided, node name will be chosen.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * Regulator bind:
52*4882a593Smuzhiyun  * For each regulator device, the device_bind() should be called with passed
53*4882a593Smuzhiyun  * device tree offset. This is required for this uclass's '.post_bind' method,
54*4882a593Smuzhiyun  * which does the scan on the device node, for the 'regulator-name' constraint.
55*4882a593Smuzhiyun  * If the parent is not a PMIC device, and the child is not bind by function:
56*4882a593Smuzhiyun  * 'pmic_bind_childs()', then it's recommended to bind the device by call to
57*4882a593Smuzhiyun  * dm_scan_fdt_dev() - this is usually done automatically for bus devices,
58*4882a593Smuzhiyun  * as a post bind method.
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * Regulator get:
61*4882a593Smuzhiyun  * Having the device's name constraint, we can call regulator_by_platname(),
62*4882a593Smuzhiyun  * to find the required regulator. Before return, the regulator is probed,
63*4882a593Smuzhiyun  * and the rest of its constraints are put into the device's uclass platform
64*4882a593Smuzhiyun  * data, by the uclass regulator '.pre_probe' method.
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  * For more info about PMIC bind, please refer to file: 'include/power/pmic.h'
67*4882a593Smuzhiyun  *
68*4882a593Smuzhiyun  * Note:
69*4882a593Smuzhiyun  * Please do not use the device_bind_by_name() function, since it pass '-1' as
70*4882a593Smuzhiyun  * device node offset - and the bind will fail on uclass .post_bind method,
71*4882a593Smuzhiyun  * because of missing 'regulator-name' constraint.
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  *
74*4882a593Smuzhiyun  * Fixed Voltage/Current Regulator
75*4882a593Smuzhiyun  * ===============================
76*4882a593Smuzhiyun  *
77*4882a593Smuzhiyun  * When fixed voltage regulator is needed, then enable the config:
78*4882a593Smuzhiyun  * - CONFIG_DM_REGULATOR_FIXED
79*4882a593Smuzhiyun  *
80*4882a593Smuzhiyun  * The driver file: 'drivers/power/regulator/fixed.c', provides basic support
81*4882a593Smuzhiyun  * for control the GPIO, and return the device tree constraint values.
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  * To bind the fixed voltage regulator device, we usually use a 'simple-bus'
84*4882a593Smuzhiyun  * node as a parent. And 'regulator-fixed' for the driver compatible. This is
85*4882a593Smuzhiyun  * the same as in the kernel. The example node of fixed regulator:
86*4882a593Smuzhiyun  *
87*4882a593Smuzhiyun  * simple-bus {
88*4882a593Smuzhiyun  *     compatible = "simple-bus";
89*4882a593Smuzhiyun  *     #address-cells = <1>;
90*4882a593Smuzhiyun  *     #size-cells = <0>;
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  *     blue_led {
93*4882a593Smuzhiyun  *         compatible = "regulator-fixed";
94*4882a593Smuzhiyun  *         regulator-name = "VDD_LED_3.3V";
95*4882a593Smuzhiyun  *         regulator-min-microvolt = <3300000>;
96*4882a593Smuzhiyun  *         regulator-max-microvolt = <3300000>;
97*4882a593Smuzhiyun  *         gpio = <&gpc1 0 GPIO_ACTIVE_LOW>;
98*4882a593Smuzhiyun  *     };
99*4882a593Smuzhiyun  * };
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  * The fixed regulator devices also provide regulator uclass platform data. And
102*4882a593Smuzhiyun  * devices bound from such node, can use the regulator drivers API.
103*4882a593Smuzhiyun */
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /* enum regulator_type - used for regulator_*() variant calls */
106*4882a593Smuzhiyun enum regulator_type {
107*4882a593Smuzhiyun 	REGULATOR_TYPE_LDO = 0,
108*4882a593Smuzhiyun 	REGULATOR_TYPE_BUCK,
109*4882a593Smuzhiyun 	REGULATOR_TYPE_DVS,
110*4882a593Smuzhiyun 	REGULATOR_TYPE_FIXED,
111*4882a593Smuzhiyun 	REGULATOR_TYPE_GPIO,
112*4882a593Smuzhiyun 	REGULATOR_TYPE_OTHER,
113*4882a593Smuzhiyun };
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun /**
116*4882a593Smuzhiyun  * struct dm_regulator_mode - this structure holds an information about
117*4882a593Smuzhiyun  * each regulator operation mode. Probably in most cases - an array.
118*4882a593Smuzhiyun  * This will be probably a driver-static data, since it is device-specific.
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  * @id             - a driver-specific mode id
121*4882a593Smuzhiyun  * @register_value - a driver-specific value for its mode id
122*4882a593Smuzhiyun  * @name           - the name of mode - used for regulator command
123*4882a593Smuzhiyun  * Note:
124*4882a593Smuzhiyun  * The field 'id', should be always a positive number, since the negative values
125*4882a593Smuzhiyun  * are reserved for the errno numbers when returns the mode id.
126*4882a593Smuzhiyun  */
127*4882a593Smuzhiyun struct dm_regulator_mode {
128*4882a593Smuzhiyun 	int id; /* Set only as >= 0 (negative value is reserved for errno) */
129*4882a593Smuzhiyun 	int register_value;
130*4882a593Smuzhiyun 	const char *name;
131*4882a593Smuzhiyun };
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun enum regulator_flag {
134*4882a593Smuzhiyun 	REGULATOR_FLAG_AUTOSET_UV	= 1 << 0,
135*4882a593Smuzhiyun 	REGULATOR_FLAG_AUTOSET_UA	= 1 << 1,
136*4882a593Smuzhiyun };
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /**
139*4882a593Smuzhiyun  * struct dm_regulator_uclass_platdata - pointed by dev->uclass_platdata, and
140*4882a593Smuzhiyun  * allocated on each regulator bind. This structure holds an information
141*4882a593Smuzhiyun  * about each regulator's constraints and supported operation modes.
142*4882a593Smuzhiyun  * There is no "step" voltage value - so driver should take care of this.
143*4882a593Smuzhiyun  *
144*4882a593Smuzhiyun  * @type       - one of 'enum regulator_type'
145*4882a593Smuzhiyun  * @mode       - pointer to the regulator mode (array if more than one)
146*4882a593Smuzhiyun  * @mode_count - number of '.mode' entries
147*4882a593Smuzhiyun  * @min_uV*    - minimum voltage (micro Volts)
148*4882a593Smuzhiyun  * @max_uV*    - maximum voltage (micro Volts)
149*4882a593Smuzhiyun  * @min_uA*    - minimum amperage (micro Amps)
150*4882a593Smuzhiyun  * @max_uA*    - maximum amperage (micro Amps)
151*4882a593Smuzhiyun  * @always_on* - bool type, true or false
152*4882a593Smuzhiyun  * @boot_on*   - bool type, true or false
153*4882a593Smuzhiyun  * TODO(sjg@chromium.org): Consider putting the above two into @flags
154*4882a593Smuzhiyun  * @flags:     - flags value (see REGULATOR_FLAG_...)
155*4882a593Smuzhiyun  * @name**     - fdt regulator name - should be taken from the device tree
156*4882a593Smuzhiyun  * ctrl_reg:   - Control register offset used to enable/disable regulator
157*4882a593Smuzhiyun  * volt_reg:   - register offset for writing voltage vsel values
158*4882a593Smuzhiyun  *
159*4882a593Smuzhiyun  * Note:
160*4882a593Smuzhiyun  * *  - set automatically on device probe by the uclass's '.pre_probe' method.
161*4882a593Smuzhiyun  * ** - set automatically on device bind by the uclass's '.post_bind' method.
162*4882a593Smuzhiyun  * The constraints: type, mode, mode_count, can be set by device driver, e.g.
163*4882a593Smuzhiyun  * by the driver '.probe' method.
164*4882a593Smuzhiyun  */
165*4882a593Smuzhiyun struct dm_regulator_uclass_platdata {
166*4882a593Smuzhiyun 	enum regulator_type type;
167*4882a593Smuzhiyun 	struct dm_regulator_mode *mode;
168*4882a593Smuzhiyun 	int mode_count;
169*4882a593Smuzhiyun 	int min_uV;
170*4882a593Smuzhiyun 	int max_uV;
171*4882a593Smuzhiyun 	int init_uV;
172*4882a593Smuzhiyun 	int min_uA;
173*4882a593Smuzhiyun 	int max_uA;
174*4882a593Smuzhiyun 	bool always_on;
175*4882a593Smuzhiyun 	bool boot_on;
176*4882a593Smuzhiyun 	const char *name;
177*4882a593Smuzhiyun 	int flags;
178*4882a593Smuzhiyun 	u8 ctrl_reg;
179*4882a593Smuzhiyun 	u8 volt_reg;
180*4882a593Smuzhiyun 	bool suspend_on;
181*4882a593Smuzhiyun 	bool ignore;
182*4882a593Smuzhiyun 	u32 suspend_uV;
183*4882a593Smuzhiyun 	u32 ramp_delay;
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun /* Regulator device operations */
187*4882a593Smuzhiyun struct dm_regulator_ops {
188*4882a593Smuzhiyun 	/**
189*4882a593Smuzhiyun 	 * The regulator output value function calls operates on a micro Volts.
190*4882a593Smuzhiyun 	 *
191*4882a593Smuzhiyun 	 * get/set_value - get/set output value of the given output number
192*4882a593Smuzhiyun 	 * @dev          - regulator device
193*4882a593Smuzhiyun 	 * Sets:
194*4882a593Smuzhiyun 	 * @uV           - set the output value [micro Volts]
195*4882a593Smuzhiyun 	 * @return output value [uV] on success or negative errno if fail.
196*4882a593Smuzhiyun 	 */
197*4882a593Smuzhiyun 	int (*get_value)(struct udevice *dev);
198*4882a593Smuzhiyun 	int (*set_value)(struct udevice *dev, int uV);
199*4882a593Smuzhiyun 	int (*set_suspend_value)(struct udevice *dev, int uV);
200*4882a593Smuzhiyun 	int (*get_suspend_value)(struct udevice *dev);
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	/**
203*4882a593Smuzhiyun 	 * The regulator output current function calls operates on a micro Amps.
204*4882a593Smuzhiyun 	 *
205*4882a593Smuzhiyun 	 * get/set_current - get/set output current of the given output number
206*4882a593Smuzhiyun 	 * @dev            - regulator device
207*4882a593Smuzhiyun 	 * Sets:
208*4882a593Smuzhiyun 	 * @uA           - set the output current [micro Amps]
209*4882a593Smuzhiyun 	 * @return output value [uA] on success or negative errno if fail.
210*4882a593Smuzhiyun 	 */
211*4882a593Smuzhiyun 	int (*get_current)(struct udevice *dev);
212*4882a593Smuzhiyun 	int (*set_current)(struct udevice *dev, int uA);
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun 	/**
215*4882a593Smuzhiyun 	 * The most basic feature of the regulator output is its enable state.
216*4882a593Smuzhiyun 	 *
217*4882a593Smuzhiyun 	 * get/set_enable - get/set enable state of the given output number
218*4882a593Smuzhiyun 	 * @dev           - regulator device
219*4882a593Smuzhiyun 	 * Sets:
220*4882a593Smuzhiyun 	 * @enable         - set true - enable or false - disable
221*4882a593Smuzhiyun 	 * @return true/false for get or -errno if fail; 0 / -errno for set.
222*4882a593Smuzhiyun 	 */
223*4882a593Smuzhiyun 	int (*get_enable)(struct udevice *dev);
224*4882a593Smuzhiyun 	int (*set_enable)(struct udevice *dev, bool enable);
225*4882a593Smuzhiyun 	int (*set_suspend_enable)(struct udevice *dev, bool enable);
226*4882a593Smuzhiyun 	int (*get_suspend_enable)(struct udevice *dev);
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun 	/**
229*4882a593Smuzhiyun 	 * The 'get/set_mode()' function calls should operate on a driver-
230*4882a593Smuzhiyun 	 * specific mode id definitions, which should be found in:
231*4882a593Smuzhiyun 	 * field 'id' of struct dm_regulator_mode.
232*4882a593Smuzhiyun 	 *
233*4882a593Smuzhiyun 	 * get/set_mode - get/set operation mode of the given output number
234*4882a593Smuzhiyun 	 * @dev         - regulator device
235*4882a593Smuzhiyun 	 * Sets
236*4882a593Smuzhiyun 	 * @mode_id     - set output mode id (struct dm_regulator_mode->id)
237*4882a593Smuzhiyun 	 * @return id/0 for get/set on success or negative errno if fail.
238*4882a593Smuzhiyun 	 * Note:
239*4882a593Smuzhiyun 	 * The field 'id' of struct type 'dm_regulator_mode', should be always
240*4882a593Smuzhiyun 	 * a positive number, since the negative is reserved for the error.
241*4882a593Smuzhiyun 	 */
242*4882a593Smuzhiyun 	int (*get_mode)(struct udevice *dev);
243*4882a593Smuzhiyun 	int (*set_mode)(struct udevice *dev, int mode_id);
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun 	/**
246*4882a593Smuzhiyun 	 * The regulator voltage set ramp delay
247*4882a593Smuzhiyun 	 *
248*4882a593Smuzhiyun 	 * @dev            - regulator device
249*4882a593Smuzhiyun 	 * @ramp_delay     - ramp delay [uV/uS]
250*4882a593Smuzhiyun 	 * @return zero on success and other failed.
251*4882a593Smuzhiyun 	 */
252*4882a593Smuzhiyun 	int (*set_ramp_delay)(struct udevice *dev, u32 ramp_delay);
253*4882a593Smuzhiyun };
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun /**
256*4882a593Smuzhiyun  * regulator_mode: returns a pointer to the array of regulator mode info
257*4882a593Smuzhiyun  *
258*4882a593Smuzhiyun  * @dev        - pointer to the regulator device
259*4882a593Smuzhiyun  * @modep      - pointer to the returned mode info array
260*4882a593Smuzhiyun  * @return     - count of modep entries on success or negative errno if fail.
261*4882a593Smuzhiyun  */
262*4882a593Smuzhiyun int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep);
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun /**
265*4882a593Smuzhiyun  * regulator_get_value: get microvoltage voltage value of a given regulator
266*4882a593Smuzhiyun  *
267*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
268*4882a593Smuzhiyun  * @return - positive output value [uV] on success or negative errno if fail.
269*4882a593Smuzhiyun  */
270*4882a593Smuzhiyun int regulator_get_value(struct udevice *dev);
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun /**
273*4882a593Smuzhiyun  * regulator_set_value: set the microvoltage value of a given regulator.
274*4882a593Smuzhiyun  *
275*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
276*4882a593Smuzhiyun  * @uV     - the output value to set [micro Volts]
277*4882a593Smuzhiyun  * @return - 0 on success or -errno val if fails
278*4882a593Smuzhiyun  */
279*4882a593Smuzhiyun int regulator_set_value(struct udevice *dev, int uV);
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun /**
282*4882a593Smuzhiyun  * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator.
283*4882a593Smuzhiyun  *
284*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
285*4882a593Smuzhiyun  * @uV     - the output suspend value to set [micro Volts]
286*4882a593Smuzhiyun  * @return - 0 on success or -errno val if fails
287*4882a593Smuzhiyun  */
288*4882a593Smuzhiyun int regulator_set_suspend_value(struct udevice *dev, int uV);
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun /**
291*4882a593Smuzhiyun  * regulator_get_suspend_value: get the suspend microvoltage value of a given regulator.
292*4882a593Smuzhiyun  *
293*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
294*4882a593Smuzhiyun  * @return - positive output value [uV] on success or negative errno if fail.
295*4882a593Smuzhiyun  */
296*4882a593Smuzhiyun int regulator_get_suspend_value(struct udevice *dev);
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun /**
299*4882a593Smuzhiyun  * regulator_set_value_force: set the microvoltage value of a given regulator
300*4882a593Smuzhiyun  *			      without any min-,max condition check
301*4882a593Smuzhiyun  *
302*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
303*4882a593Smuzhiyun  * @uV     - the output value to set [micro Volts]
304*4882a593Smuzhiyun  * @return - 0 on success or -errno val if fails
305*4882a593Smuzhiyun  */
306*4882a593Smuzhiyun int regulator_set_value_force(struct udevice *dev, int uV);
307*4882a593Smuzhiyun 
308*4882a593Smuzhiyun /**
309*4882a593Smuzhiyun  * regulator_get_current: get microampere value of a given regulator
310*4882a593Smuzhiyun  *
311*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
312*4882a593Smuzhiyun  * @return - positive output current [uA] on success or negative errno if fail.
313*4882a593Smuzhiyun  */
314*4882a593Smuzhiyun int regulator_get_current(struct udevice *dev);
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun /**
317*4882a593Smuzhiyun  * regulator_set_current: set the microampere value of a given regulator.
318*4882a593Smuzhiyun  *
319*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
320*4882a593Smuzhiyun  * @uA     - set the output current [micro Amps]
321*4882a593Smuzhiyun  * @return - 0 on success or -errno val if fails
322*4882a593Smuzhiyun  */
323*4882a593Smuzhiyun int regulator_set_current(struct udevice *dev, int uA);
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun /**
326*4882a593Smuzhiyun  * regulator_get_enable: get regulator device enable state.
327*4882a593Smuzhiyun  *
328*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
329*4882a593Smuzhiyun  * @return - true/false of enable state or -errno val if fails
330*4882a593Smuzhiyun  */
331*4882a593Smuzhiyun int regulator_get_enable(struct udevice *dev);
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun /**
334*4882a593Smuzhiyun  * regulator_set_enable: set regulator enable state
335*4882a593Smuzhiyun  *
336*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
337*4882a593Smuzhiyun  * @enable - set true or false
338*4882a593Smuzhiyun  * @return - 0 on success or -errno val if fails
339*4882a593Smuzhiyun  */
340*4882a593Smuzhiyun int regulator_set_enable(struct udevice *dev, bool enable);
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun /**
343*4882a593Smuzhiyun  * regulator_set_suspend_enable: set regulator suspend enable state
344*4882a593Smuzhiyun  *
345*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
346*4882a593Smuzhiyun  * @enable - set true or false
347*4882a593Smuzhiyun  * @return - 0 on success or -errno val if fails
348*4882a593Smuzhiyun  */
349*4882a593Smuzhiyun int regulator_set_suspend_enable(struct udevice *dev, bool enable);
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun /**
352*4882a593Smuzhiyun  * regulator_get_suspend_enable: get regulator suspend enable state
353*4882a593Smuzhiyun  *
354*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
355*4882a593Smuzhiyun  * @return - 0 on success or -errno val if fails
356*4882a593Smuzhiyun  */
357*4882a593Smuzhiyun int regulator_get_suspend_enable(struct udevice *dev);
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun /**
360*4882a593Smuzhiyun  * regulator_get_mode: get active operation mode id of a given regulator
361*4882a593Smuzhiyun  *
362*4882a593Smuzhiyun  * @dev    - pointer to the regulator device
363*4882a593Smuzhiyun  * @return - positive mode 'id' number on success or -errno val if fails
364*4882a593Smuzhiyun  * Note:
365*4882a593Smuzhiyun  * The device can provide an array of operating modes, which is type of struct
366*4882a593Smuzhiyun  * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
367*4882a593Smuzhiyun  * that array. By calling this function, the driver should return an active mode
368*4882a593Smuzhiyun  * id of the given regulator device.
369*4882a593Smuzhiyun  */
370*4882a593Smuzhiyun int regulator_get_mode(struct udevice *dev);
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun /**
373*4882a593Smuzhiyun  * regulator_set_mode: set the given regulator's, active mode id
374*4882a593Smuzhiyun  *
375*4882a593Smuzhiyun  * @dev     - pointer to the regulator device
376*4882a593Smuzhiyun  * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode)
377*4882a593Smuzhiyun  * @return  - 0 on success or -errno value if fails
378*4882a593Smuzhiyun  * Note:
379*4882a593Smuzhiyun  * The device can provide an array of operating modes, which is type of struct
380*4882a593Smuzhiyun  * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
381*4882a593Smuzhiyun  * that array. By calling this function, the driver should set the active mode
382*4882a593Smuzhiyun  * of a given regulator to given by "mode_id" argument.
383*4882a593Smuzhiyun  */
384*4882a593Smuzhiyun int regulator_set_mode(struct udevice *dev, int mode_id);
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun /**
387*4882a593Smuzhiyun  * regulators_enable_boot_on() - enable regulators needed for boot
388*4882a593Smuzhiyun  *
389*4882a593Smuzhiyun  * This enables all regulators which are marked to be on at boot time. This
390*4882a593Smuzhiyun  * only works for regulators which don't have a range for voltage/current,
391*4882a593Smuzhiyun  * since in that case it is not possible to know which value to use.
392*4882a593Smuzhiyun  *
393*4882a593Smuzhiyun  * This effectively calls regulator_autoset() for every regulator.
394*4882a593Smuzhiyun  */
395*4882a593Smuzhiyun int regulators_enable_boot_on(bool verbose);
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun /**
398*4882a593Smuzhiyun  * regulators_enable_state_mem() - enable regulators state mem configure
399*4882a593Smuzhiyun  *
400*4882a593Smuzhiyun  * This sets regulator-state-mem state for all regulators ;
401*4882a593Smuzhiyun  */
402*4882a593Smuzhiyun int regulators_enable_state_mem(bool verbose);
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun /**
405*4882a593Smuzhiyun  * regulator_autoset_by_name: setup the regulator given by its uclass's
406*4882a593Smuzhiyun  * platform data name field. The setup depends on constraints found in device's
407*4882a593Smuzhiyun  * uclass's platform data (struct dm_regulator_uclass_platdata):
408*4882a593Smuzhiyun  * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
409*4882a593Smuzhiyun  *   or if both are unset, then the function returns
410*4882a593Smuzhiyun  * - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
411*4882a593Smuzhiyun  * - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
412*4882a593Smuzhiyun  *
413*4882a593Smuzhiyun  * The function returns on first encountered error.
414*4882a593Smuzhiyun  *
415*4882a593Smuzhiyun  * @platname - expected string for dm_regulator_uclass_platdata .name field
416*4882a593Smuzhiyun  * @devp     - returned pointer to the regulator device - if non-NULL passed
417*4882a593Smuzhiyun  * @return: 0 on success or negative value of errno.
418*4882a593Smuzhiyun  *
419*4882a593Smuzhiyun  * The returned 'regulator' device can be used with:
420*4882a593Smuzhiyun  * - regulator_get/set_*
421*4882a593Smuzhiyun  */
422*4882a593Smuzhiyun int regulator_autoset_by_name(const char *platname, struct udevice **devp);
423*4882a593Smuzhiyun 
424*4882a593Smuzhiyun /**
425*4882a593Smuzhiyun  * regulator_list_autoset: setup the regulators given by list of their uclass's
426*4882a593Smuzhiyun  * platform data name field. The setup depends on constraints found in device's
427*4882a593Smuzhiyun  * uclass's platform data. The function loops with calls to:
428*4882a593Smuzhiyun  * regulator_autoset_by_name() for each name from the list.
429*4882a593Smuzhiyun  *
430*4882a593Smuzhiyun  * @list_platname - an array of expected strings for .name field of each
431*4882a593Smuzhiyun  *                  regulator's uclass platdata
432*4882a593Smuzhiyun  * @list_devp     - an array of returned pointers to the successfully setup
433*4882a593Smuzhiyun  *                  regulator devices if non-NULL passed
434*4882a593Smuzhiyun  * @verbose       - (true/false) print each regulator setup info, or be quiet
435*4882a593Smuzhiyun  * @return 0 on successfully setup of all list entries, otherwise first error.
436*4882a593Smuzhiyun  *
437*4882a593Smuzhiyun  * The returned 'regulator' devices can be used with:
438*4882a593Smuzhiyun  * - regulator_get/set_*
439*4882a593Smuzhiyun  *
440*4882a593Smuzhiyun  * Note: The list must ends with NULL entry, like in the "platname" list below:
441*4882a593Smuzhiyun  * char *my_regulators[] = {
442*4882a593Smuzhiyun  *     "VCC_3.3V",
443*4882a593Smuzhiyun  *     "VCC_1.8V",
444*4882a593Smuzhiyun  *     NULL,
445*4882a593Smuzhiyun  * };
446*4882a593Smuzhiyun  */
447*4882a593Smuzhiyun int regulator_list_autoset(const char *list_platname[],
448*4882a593Smuzhiyun 			   struct udevice *list_devp[],
449*4882a593Smuzhiyun 			   bool verbose);
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun /**
452*4882a593Smuzhiyun  * regulator_get_by_devname: returns the pointer to the pmic regulator device.
453*4882a593Smuzhiyun  * Search by name, found in regulator device's name.
454*4882a593Smuzhiyun  *
455*4882a593Smuzhiyun  * @devname - expected string for 'dev->name' of regulator device
456*4882a593Smuzhiyun  * @devp    - returned pointer to the regulator device
457*4882a593Smuzhiyun  * @return 0 on success or negative value of errno.
458*4882a593Smuzhiyun  *
459*4882a593Smuzhiyun  * The returned 'regulator' device is probed and can be used with:
460*4882a593Smuzhiyun  * - regulator_get/set_*
461*4882a593Smuzhiyun  */
462*4882a593Smuzhiyun int regulator_get_by_devname(const char *devname, struct udevice **devp);
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun /**
465*4882a593Smuzhiyun  * regulator_get_by_platname: returns the pointer to the pmic regulator device.
466*4882a593Smuzhiyun  * Search by name, found in regulator uclass platdata.
467*4882a593Smuzhiyun  *
468*4882a593Smuzhiyun  * @platname - expected string for uc_pdata->name of regulator uclass platdata
469*4882a593Smuzhiyun  * @devp     - returns pointer to the regulator device or NULL on error
470*4882a593Smuzhiyun  * @return 0 on success or negative value of errno.
471*4882a593Smuzhiyun  *
472*4882a593Smuzhiyun  * The returned 'regulator' device is probed and can be used with:
473*4882a593Smuzhiyun  * - regulator_get/set_*
474*4882a593Smuzhiyun  */
475*4882a593Smuzhiyun int regulator_get_by_platname(const char *platname, struct udevice **devp);
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun /**
478*4882a593Smuzhiyun  * device_get_supply_regulator: returns the pointer to the supply regulator.
479*4882a593Smuzhiyun  * Search by phandle, found in device's node.
480*4882a593Smuzhiyun  *
481*4882a593Smuzhiyun  * Note: Please pay attention to proper order of device bind sequence.
482*4882a593Smuzhiyun  * The regulator device searched by the phandle, must be binded before
483*4882a593Smuzhiyun  * this function call.
484*4882a593Smuzhiyun  *
485*4882a593Smuzhiyun  * @dev         - device with supply phandle
486*4882a593Smuzhiyun  * @supply_name - phandle name of regulator
487*4882a593Smuzhiyun  * @devp        - returned pointer to the supply device
488*4882a593Smuzhiyun  * @return 0 on success or negative value of errno.
489*4882a593Smuzhiyun  */
490*4882a593Smuzhiyun int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
491*4882a593Smuzhiyun 				struct udevice **devp);
492*4882a593Smuzhiyun 
493*4882a593Smuzhiyun #endif /* _INCLUDE_REGULATOR_H_ */
494