xref: /OK3568_Linux_fs/kernel/include/linux/regulator/driver.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * driver.h -- SoC Regulator driver support.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Regulator Driver Interface.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #ifndef __LINUX_REGULATOR_DRIVER_H_
13*4882a593Smuzhiyun #define __LINUX_REGULATOR_DRIVER_H_
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <linux/device.h>
16*4882a593Smuzhiyun #include <linux/linear_range.h>
17*4882a593Smuzhiyun #include <linux/notifier.h>
18*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
19*4882a593Smuzhiyun #include <linux/ww_mutex.h>
20*4882a593Smuzhiyun #include <linux/android_kabi.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun struct gpio_desc;
23*4882a593Smuzhiyun struct regmap;
24*4882a593Smuzhiyun struct regulator_dev;
25*4882a593Smuzhiyun struct regulator_config;
26*4882a593Smuzhiyun struct regulator_init_data;
27*4882a593Smuzhiyun struct regulator_enable_gpio;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun enum regulator_status {
30*4882a593Smuzhiyun 	REGULATOR_STATUS_OFF,
31*4882a593Smuzhiyun 	REGULATOR_STATUS_ON,
32*4882a593Smuzhiyun 	REGULATOR_STATUS_ERROR,
33*4882a593Smuzhiyun 	/* fast/normal/idle/standby are flavors of "on" */
34*4882a593Smuzhiyun 	REGULATOR_STATUS_FAST,
35*4882a593Smuzhiyun 	REGULATOR_STATUS_NORMAL,
36*4882a593Smuzhiyun 	REGULATOR_STATUS_IDLE,
37*4882a593Smuzhiyun 	REGULATOR_STATUS_STANDBY,
38*4882a593Smuzhiyun 	/* The regulator is enabled but not regulating */
39*4882a593Smuzhiyun 	REGULATOR_STATUS_BYPASS,
40*4882a593Smuzhiyun 	/* in case that any other status doesn't apply */
41*4882a593Smuzhiyun 	REGULATOR_STATUS_UNDEFINED,
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /* Initialize struct linear_range for regulators */
45*4882a593Smuzhiyun #define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV)	\
46*4882a593Smuzhiyun {									\
47*4882a593Smuzhiyun 	.min		= _min_uV,					\
48*4882a593Smuzhiyun 	.min_sel	= _min_sel,					\
49*4882a593Smuzhiyun 	.max_sel	= _max_sel,					\
50*4882a593Smuzhiyun 	.step		= _step_uV,					\
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /**
54*4882a593Smuzhiyun  * struct regulator_ops - regulator operations.
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  * @enable: Configure the regulator as enabled.
57*4882a593Smuzhiyun  * @disable: Configure the regulator as disabled.
58*4882a593Smuzhiyun  * @is_enabled: Return 1 if the regulator is enabled, 0 if not.
59*4882a593Smuzhiyun  *		May also return negative errno.
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  * @set_voltage: Set the voltage for the regulator within the range specified.
62*4882a593Smuzhiyun  *               The driver should select the voltage closest to min_uV.
63*4882a593Smuzhiyun  * @set_voltage_sel: Set the voltage for the regulator using the specified
64*4882a593Smuzhiyun  *                   selector.
65*4882a593Smuzhiyun  * @map_voltage: Convert a voltage into a selector
66*4882a593Smuzhiyun  * @get_voltage: Return the currently configured voltage for the regulator;
67*4882a593Smuzhiyun  *                   return -ENOTRECOVERABLE if regulator can't be read at
68*4882a593Smuzhiyun  *                   bootup and hasn't been set yet.
69*4882a593Smuzhiyun  * @get_voltage_sel: Return the currently configured voltage selector for the
70*4882a593Smuzhiyun  *                   regulator; return -ENOTRECOVERABLE if regulator can't
71*4882a593Smuzhiyun  *                   be read at bootup and hasn't been set yet.
72*4882a593Smuzhiyun  * @list_voltage: Return one of the supported voltages, in microvolts; zero
73*4882a593Smuzhiyun  *	if the selector indicates a voltage that is unusable on this system;
74*4882a593Smuzhiyun  *	or negative errno.  Selectors range from zero to one less than
75*4882a593Smuzhiyun  *	regulator_desc.n_voltages.  Voltages may be reported in any order.
76*4882a593Smuzhiyun  *
77*4882a593Smuzhiyun  * @set_current_limit: Configure a limit for a current-limited regulator.
78*4882a593Smuzhiyun  *                     The driver should select the current closest to max_uA.
79*4882a593Smuzhiyun  * @get_current_limit: Get the configured limit for a current-limited regulator.
80*4882a593Smuzhiyun  * @set_input_current_limit: Configure an input limit.
81*4882a593Smuzhiyun  *
82*4882a593Smuzhiyun  * @set_over_current_protection: Support capability of automatically shutting
83*4882a593Smuzhiyun  *                               down when detecting an over current event.
84*4882a593Smuzhiyun  *
85*4882a593Smuzhiyun  * @set_active_discharge: Set active discharge enable/disable of regulators.
86*4882a593Smuzhiyun  *
87*4882a593Smuzhiyun  * @set_mode: Set the configured operating mode for the regulator.
88*4882a593Smuzhiyun  * @get_mode: Get the configured operating mode for the regulator.
89*4882a593Smuzhiyun  * @get_error_flags: Get the current error(s) for the regulator.
90*4882a593Smuzhiyun  * @get_status: Return actual (not as-configured) status of regulator, as a
91*4882a593Smuzhiyun  *	REGULATOR_STATUS value (or negative errno)
92*4882a593Smuzhiyun  * @get_optimum_mode: Get the most efficient operating mode for the regulator
93*4882a593Smuzhiyun  *                    when running with the specified parameters.
94*4882a593Smuzhiyun  * @set_load: Set the load for the regulator.
95*4882a593Smuzhiyun  *
96*4882a593Smuzhiyun  * @set_bypass: Set the regulator in bypass mode.
97*4882a593Smuzhiyun  * @get_bypass: Get the regulator bypass mode state.
98*4882a593Smuzhiyun  *
99*4882a593Smuzhiyun  * @enable_time: Time taken for the regulator voltage output voltage to
100*4882a593Smuzhiyun  *               stabilise after being enabled, in microseconds.
101*4882a593Smuzhiyun  * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
102*4882a593Smuzhiyun  *		select ramp delay equal to or less than(closest) ramp_delay.
103*4882a593Smuzhiyun  * @set_voltage_time: Time taken for the regulator voltage output voltage
104*4882a593Smuzhiyun  *               to stabilise after being set to a new value, in microseconds.
105*4882a593Smuzhiyun  *               The function receives the from and to voltage as input, it
106*4882a593Smuzhiyun  *               should return the worst case.
107*4882a593Smuzhiyun  * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
108*4882a593Smuzhiyun  *               to stabilise after being set to a new value, in microseconds.
109*4882a593Smuzhiyun  *               The function receives the from and to voltage selector as
110*4882a593Smuzhiyun  *               input, it should return the worst case.
111*4882a593Smuzhiyun  * @set_soft_start: Enable soft start for the regulator.
112*4882a593Smuzhiyun  *
113*4882a593Smuzhiyun  * @set_suspend_voltage: Set the voltage for the regulator when the system
114*4882a593Smuzhiyun  *                       is suspended.
115*4882a593Smuzhiyun  * @set_suspend_enable: Mark the regulator as enabled when the system is
116*4882a593Smuzhiyun  *                      suspended.
117*4882a593Smuzhiyun  * @set_suspend_disable: Mark the regulator as disabled when the system is
118*4882a593Smuzhiyun  *                       suspended.
119*4882a593Smuzhiyun  * @set_suspend_mode: Set the operating mode for the regulator when the
120*4882a593Smuzhiyun  *                    system is suspended.
121*4882a593Smuzhiyun  * @resume: Resume operation of suspended regulator.
122*4882a593Smuzhiyun  * @set_pull_down: Configure the regulator to pull down when the regulator
123*4882a593Smuzhiyun  *		   is disabled.
124*4882a593Smuzhiyun  *
125*4882a593Smuzhiyun  * This struct describes regulator operations which can be implemented by
126*4882a593Smuzhiyun  * regulator chip drivers.
127*4882a593Smuzhiyun  */
128*4882a593Smuzhiyun struct regulator_ops {
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	/* enumerate supported voltages */
131*4882a593Smuzhiyun 	int (*list_voltage) (struct regulator_dev *, unsigned selector);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	/* get/set regulator voltage */
134*4882a593Smuzhiyun 	int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
135*4882a593Smuzhiyun 			    unsigned *selector);
136*4882a593Smuzhiyun 	int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
137*4882a593Smuzhiyun 	int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
138*4882a593Smuzhiyun 	int (*get_voltage) (struct regulator_dev *);
139*4882a593Smuzhiyun 	int (*get_voltage_sel) (struct regulator_dev *);
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	/* get/set regulator current  */
142*4882a593Smuzhiyun 	int (*set_current_limit) (struct regulator_dev *,
143*4882a593Smuzhiyun 				 int min_uA, int max_uA);
144*4882a593Smuzhiyun 	int (*get_current_limit) (struct regulator_dev *);
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
147*4882a593Smuzhiyun 	int (*set_over_current_protection) (struct regulator_dev *);
148*4882a593Smuzhiyun 	int (*set_active_discharge) (struct regulator_dev *, bool enable);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun 	/* enable/disable regulator */
151*4882a593Smuzhiyun 	int (*enable) (struct regulator_dev *);
152*4882a593Smuzhiyun 	int (*disable) (struct regulator_dev *);
153*4882a593Smuzhiyun 	int (*is_enabled) (struct regulator_dev *);
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	/* get/set regulator operating mode (defined in consumer.h) */
156*4882a593Smuzhiyun 	int (*set_mode) (struct regulator_dev *, unsigned int mode);
157*4882a593Smuzhiyun 	unsigned int (*get_mode) (struct regulator_dev *);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	/* retrieve current error flags on the regulator */
160*4882a593Smuzhiyun 	int (*get_error_flags)(struct regulator_dev *, unsigned int *flags);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	/* Time taken to enable or set voltage on the regulator */
163*4882a593Smuzhiyun 	int (*enable_time) (struct regulator_dev *);
164*4882a593Smuzhiyun 	int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
165*4882a593Smuzhiyun 	int (*set_voltage_time) (struct regulator_dev *, int old_uV,
166*4882a593Smuzhiyun 				 int new_uV);
167*4882a593Smuzhiyun 	int (*set_voltage_time_sel) (struct regulator_dev *,
168*4882a593Smuzhiyun 				     unsigned int old_selector,
169*4882a593Smuzhiyun 				     unsigned int new_selector);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	int (*set_soft_start) (struct regulator_dev *);
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	/* report regulator status ... most other accessors report
174*4882a593Smuzhiyun 	 * control inputs, this reports results of combining inputs
175*4882a593Smuzhiyun 	 * from Linux (and other sources) with the actual load.
176*4882a593Smuzhiyun 	 * returns REGULATOR_STATUS_* or negative errno.
177*4882a593Smuzhiyun 	 */
178*4882a593Smuzhiyun 	int (*get_status)(struct regulator_dev *);
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	/* get most efficient regulator operating mode for load */
181*4882a593Smuzhiyun 	unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
182*4882a593Smuzhiyun 					  int output_uV, int load_uA);
183*4882a593Smuzhiyun 	/* set the load on the regulator */
184*4882a593Smuzhiyun 	int (*set_load)(struct regulator_dev *, int load_uA);
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	/* control and report on bypass mode */
187*4882a593Smuzhiyun 	int (*set_bypass)(struct regulator_dev *dev, bool enable);
188*4882a593Smuzhiyun 	int (*get_bypass)(struct regulator_dev *dev, bool *enable);
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun 	/* the operations below are for configuration of regulator state when
191*4882a593Smuzhiyun 	 * its parent PMIC enters a global STANDBY/HIBERNATE state */
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun 	/* set regulator suspend voltage */
194*4882a593Smuzhiyun 	int (*set_suspend_voltage) (struct regulator_dev *, int uV);
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	/* enable/disable regulator in suspend state */
197*4882a593Smuzhiyun 	int (*set_suspend_enable) (struct regulator_dev *);
198*4882a593Smuzhiyun 	int (*set_suspend_disable) (struct regulator_dev *);
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 	/* set regulator suspend operating mode (defined in consumer.h) */
201*4882a593Smuzhiyun 	int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	int (*resume)(struct regulator_dev *rdev);
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	int (*set_pull_down) (struct regulator_dev *);
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
208*4882a593Smuzhiyun };
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun /*
211*4882a593Smuzhiyun  * Regulators can either control voltage or current.
212*4882a593Smuzhiyun  */
213*4882a593Smuzhiyun enum regulator_type {
214*4882a593Smuzhiyun 	REGULATOR_VOLTAGE,
215*4882a593Smuzhiyun 	REGULATOR_CURRENT,
216*4882a593Smuzhiyun };
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun /**
219*4882a593Smuzhiyun  * struct regulator_desc - Static regulator descriptor
220*4882a593Smuzhiyun  *
221*4882a593Smuzhiyun  * Each regulator registered with the core is described with a
222*4882a593Smuzhiyun  * structure of this type and a struct regulator_config.  This
223*4882a593Smuzhiyun  * structure contains the non-varying parts of the regulator
224*4882a593Smuzhiyun  * description.
225*4882a593Smuzhiyun  *
226*4882a593Smuzhiyun  * @name: Identifying name for the regulator.
227*4882a593Smuzhiyun  * @supply_name: Identifying the regulator supply
228*4882a593Smuzhiyun  * @of_match: Name used to identify regulator in DT.
229*4882a593Smuzhiyun  * @of_match_full_name: A flag to indicate that the of_match string, if
230*4882a593Smuzhiyun  *			present, should be matched against the node full_name.
231*4882a593Smuzhiyun  * @regulators_node: Name of node containing regulator definitions in DT.
232*4882a593Smuzhiyun  * @of_parse_cb: Optional callback called only if of_match is present.
233*4882a593Smuzhiyun  *               Will be called for each regulator parsed from DT, during
234*4882a593Smuzhiyun  *               init_data parsing.
235*4882a593Smuzhiyun  *               The regulator_config passed as argument to the callback will
236*4882a593Smuzhiyun  *               be a copy of config passed to regulator_register, valid only
237*4882a593Smuzhiyun  *               for this particular call. Callback may freely change the
238*4882a593Smuzhiyun  *               config but it cannot store it for later usage.
239*4882a593Smuzhiyun  *               Callback should return 0 on success or negative ERRNO
240*4882a593Smuzhiyun  *               indicating failure.
241*4882a593Smuzhiyun  * @id: Numerical identifier for the regulator.
242*4882a593Smuzhiyun  * @ops: Regulator operations table.
243*4882a593Smuzhiyun  * @irq: Interrupt number for the regulator.
244*4882a593Smuzhiyun  * @type: Indicates if the regulator is a voltage or current regulator.
245*4882a593Smuzhiyun  * @owner: Module providing the regulator, used for refcounting.
246*4882a593Smuzhiyun  *
247*4882a593Smuzhiyun  * @continuous_voltage_range: Indicates if the regulator can set any
248*4882a593Smuzhiyun  *                            voltage within constrains range.
249*4882a593Smuzhiyun  * @n_voltages: Number of selectors available for ops.list_voltage().
250*4882a593Smuzhiyun  * @n_current_limits: Number of selectors available for current limits
251*4882a593Smuzhiyun  *
252*4882a593Smuzhiyun  * @min_uV: Voltage given by the lowest selector (if linear mapping)
253*4882a593Smuzhiyun  * @uV_step: Voltage increase with each selector (if linear mapping)
254*4882a593Smuzhiyun  * @linear_min_sel: Minimal selector for starting linear mapping
255*4882a593Smuzhiyun  * @fixed_uV: Fixed voltage of rails.
256*4882a593Smuzhiyun  * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
257*4882a593Smuzhiyun  * @min_dropout_uV: The minimum dropout voltage this regulator can handle
258*4882a593Smuzhiyun  * @linear_ranges: A constant table of possible voltage ranges.
259*4882a593Smuzhiyun  * @linear_range_selectors: A constant table of voltage range selectors.
260*4882a593Smuzhiyun  *			    If pickable ranges are used each range must
261*4882a593Smuzhiyun  *			    have corresponding selector here.
262*4882a593Smuzhiyun  * @n_linear_ranges: Number of entries in the @linear_ranges (and in
263*4882a593Smuzhiyun  *		     linear_range_selectors if used) table(s).
264*4882a593Smuzhiyun  * @volt_table: Voltage mapping table (if table based mapping)
265*4882a593Smuzhiyun  * @curr_table: Current limit mapping table (if table based mapping)
266*4882a593Smuzhiyun  *
267*4882a593Smuzhiyun  * @vsel_range_reg: Register for range selector when using pickable ranges
268*4882a593Smuzhiyun  *		    and ``regulator_map_*_voltage_*_pickable`` functions.
269*4882a593Smuzhiyun  * @vsel_range_mask: Mask for register bitfield used for range selector
270*4882a593Smuzhiyun  * @vsel_reg: Register for selector when using ``regulator_map_*_voltage_*``
271*4882a593Smuzhiyun  * @vsel_mask: Mask for register bitfield used for selector
272*4882a593Smuzhiyun  * @vsel_step: Specify the resolution of selector stepping when setting
273*4882a593Smuzhiyun  *	       voltage. If 0, then no stepping is done (requested selector is
274*4882a593Smuzhiyun  *	       set directly), if >0 then the regulator API will ramp the
275*4882a593Smuzhiyun  *	       voltage up/down gradually each time increasing/decreasing the
276*4882a593Smuzhiyun  *	       selector by the specified step value.
277*4882a593Smuzhiyun  * @csel_reg: Register for current limit selector using regmap set_current_limit
278*4882a593Smuzhiyun  * @csel_mask: Mask for register bitfield used for current limit selector
279*4882a593Smuzhiyun  * @apply_reg: Register for initiate voltage change on the output when
280*4882a593Smuzhiyun  *                using regulator_set_voltage_sel_regmap
281*4882a593Smuzhiyun  * @apply_bit: Register bitfield used for initiate voltage change on the
282*4882a593Smuzhiyun  *                output when using regulator_set_voltage_sel_regmap
283*4882a593Smuzhiyun  * @enable_reg: Register for control when using regmap enable/disable ops
284*4882a593Smuzhiyun  * @enable_mask: Mask for control when using regmap enable/disable ops
285*4882a593Smuzhiyun  * @enable_val: Enabling value for control when using regmap enable/disable ops
286*4882a593Smuzhiyun  * @disable_val: Disabling value for control when using regmap enable/disable ops
287*4882a593Smuzhiyun  * @enable_is_inverted: A flag to indicate set enable_mask bits to disable
288*4882a593Smuzhiyun  *                      when using regulator_enable_regmap and friends APIs.
289*4882a593Smuzhiyun  * @bypass_reg: Register for control when using regmap set_bypass
290*4882a593Smuzhiyun  * @bypass_mask: Mask for control when using regmap set_bypass
291*4882a593Smuzhiyun  * @bypass_val_on: Enabling value for control when using regmap set_bypass
292*4882a593Smuzhiyun  * @bypass_val_off: Disabling value for control when using regmap set_bypass
293*4882a593Smuzhiyun  * @active_discharge_off: Enabling value for control when using regmap
294*4882a593Smuzhiyun  *			  set_active_discharge
295*4882a593Smuzhiyun  * @active_discharge_on: Disabling value for control when using regmap
296*4882a593Smuzhiyun  *			 set_active_discharge
297*4882a593Smuzhiyun  * @active_discharge_mask: Mask for control when using regmap
298*4882a593Smuzhiyun  *			   set_active_discharge
299*4882a593Smuzhiyun  * @active_discharge_reg: Register for control when using regmap
300*4882a593Smuzhiyun  *			  set_active_discharge
301*4882a593Smuzhiyun  * @soft_start_reg: Register for control when using regmap set_soft_start
302*4882a593Smuzhiyun  * @soft_start_mask: Mask for control when using regmap set_soft_start
303*4882a593Smuzhiyun  * @soft_start_val_on: Enabling value for control when using regmap
304*4882a593Smuzhiyun  *                     set_soft_start
305*4882a593Smuzhiyun  * @pull_down_reg: Register for control when using regmap set_pull_down
306*4882a593Smuzhiyun  * @pull_down_mask: Mask for control when using regmap set_pull_down
307*4882a593Smuzhiyun  * @pull_down_val_on: Enabling value for control when using regmap
308*4882a593Smuzhiyun  *                     set_pull_down
309*4882a593Smuzhiyun  *
310*4882a593Smuzhiyun  * @enable_time: Time taken for initial enable of regulator (in uS).
311*4882a593Smuzhiyun  * @off_on_delay: guard time (in uS), before re-enabling a regulator
312*4882a593Smuzhiyun  *
313*4882a593Smuzhiyun  * @poll_enabled_time: The polling interval (in uS) to use while checking that
314*4882a593Smuzhiyun  *                     the regulator was actually enabled. Max upto enable_time.
315*4882a593Smuzhiyun  *
316*4882a593Smuzhiyun  * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
317*4882a593Smuzhiyun  */
318*4882a593Smuzhiyun struct regulator_desc {
319*4882a593Smuzhiyun 	const char *name;
320*4882a593Smuzhiyun 	const char *supply_name;
321*4882a593Smuzhiyun 	const char *of_match;
322*4882a593Smuzhiyun 	bool of_match_full_name;
323*4882a593Smuzhiyun 	const char *regulators_node;
324*4882a593Smuzhiyun 	int (*of_parse_cb)(struct device_node *,
325*4882a593Smuzhiyun 			    const struct regulator_desc *,
326*4882a593Smuzhiyun 			    struct regulator_config *);
327*4882a593Smuzhiyun 	int id;
328*4882a593Smuzhiyun 	unsigned int continuous_voltage_range:1;
329*4882a593Smuzhiyun 	unsigned n_voltages;
330*4882a593Smuzhiyun 	unsigned int n_current_limits;
331*4882a593Smuzhiyun 	const struct regulator_ops *ops;
332*4882a593Smuzhiyun 	int irq;
333*4882a593Smuzhiyun 	enum regulator_type type;
334*4882a593Smuzhiyun 	struct module *owner;
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	unsigned int min_uV;
337*4882a593Smuzhiyun 	unsigned int uV_step;
338*4882a593Smuzhiyun 	unsigned int linear_min_sel;
339*4882a593Smuzhiyun 	int fixed_uV;
340*4882a593Smuzhiyun 	unsigned int ramp_delay;
341*4882a593Smuzhiyun 	int min_dropout_uV;
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun 	const struct linear_range *linear_ranges;
344*4882a593Smuzhiyun 	const unsigned int *linear_range_selectors;
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun 	int n_linear_ranges;
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun 	const unsigned int *volt_table;
349*4882a593Smuzhiyun 	const unsigned int *curr_table;
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	unsigned int vsel_range_reg;
352*4882a593Smuzhiyun 	unsigned int vsel_range_mask;
353*4882a593Smuzhiyun 	unsigned int vsel_reg;
354*4882a593Smuzhiyun 	unsigned int vsel_mask;
355*4882a593Smuzhiyun 	unsigned int vsel_step;
356*4882a593Smuzhiyun 	unsigned int csel_reg;
357*4882a593Smuzhiyun 	unsigned int csel_mask;
358*4882a593Smuzhiyun 	unsigned int apply_reg;
359*4882a593Smuzhiyun 	unsigned int apply_bit;
360*4882a593Smuzhiyun 	unsigned int enable_reg;
361*4882a593Smuzhiyun 	unsigned int enable_mask;
362*4882a593Smuzhiyun 	unsigned int enable_val;
363*4882a593Smuzhiyun 	unsigned int disable_val;
364*4882a593Smuzhiyun 	bool enable_is_inverted;
365*4882a593Smuzhiyun 	unsigned int bypass_reg;
366*4882a593Smuzhiyun 	unsigned int bypass_mask;
367*4882a593Smuzhiyun 	unsigned int bypass_val_on;
368*4882a593Smuzhiyun 	unsigned int bypass_val_off;
369*4882a593Smuzhiyun 	unsigned int active_discharge_on;
370*4882a593Smuzhiyun 	unsigned int active_discharge_off;
371*4882a593Smuzhiyun 	unsigned int active_discharge_mask;
372*4882a593Smuzhiyun 	unsigned int active_discharge_reg;
373*4882a593Smuzhiyun 	unsigned int soft_start_reg;
374*4882a593Smuzhiyun 	unsigned int soft_start_mask;
375*4882a593Smuzhiyun 	unsigned int soft_start_val_on;
376*4882a593Smuzhiyun 	unsigned int pull_down_reg;
377*4882a593Smuzhiyun 	unsigned int pull_down_mask;
378*4882a593Smuzhiyun 	unsigned int pull_down_val_on;
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun 	unsigned int enable_time;
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun 	unsigned int off_on_delay;
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun 	unsigned int poll_enabled_time;
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun 	unsigned int (*of_map_mode)(unsigned int mode);
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
389*4882a593Smuzhiyun };
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun /**
392*4882a593Smuzhiyun  * struct regulator_config - Dynamic regulator descriptor
393*4882a593Smuzhiyun  *
394*4882a593Smuzhiyun  * Each regulator registered with the core is described with a
395*4882a593Smuzhiyun  * structure of this type and a struct regulator_desc.  This structure
396*4882a593Smuzhiyun  * contains the runtime variable parts of the regulator description.
397*4882a593Smuzhiyun  *
398*4882a593Smuzhiyun  * @dev: struct device for the regulator
399*4882a593Smuzhiyun  * @init_data: platform provided init data, passed through by driver
400*4882a593Smuzhiyun  * @driver_data: private regulator data
401*4882a593Smuzhiyun  * @of_node: OpenFirmware node to parse for device tree bindings (may be
402*4882a593Smuzhiyun  *           NULL).
403*4882a593Smuzhiyun  * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
404*4882a593Smuzhiyun  *          insufficient.
405*4882a593Smuzhiyun  * @ena_gpiod: GPIO controlling regulator enable.
406*4882a593Smuzhiyun  */
407*4882a593Smuzhiyun struct regulator_config {
408*4882a593Smuzhiyun 	struct device *dev;
409*4882a593Smuzhiyun 	const struct regulator_init_data *init_data;
410*4882a593Smuzhiyun 	void *driver_data;
411*4882a593Smuzhiyun 	struct device_node *of_node;
412*4882a593Smuzhiyun 	struct regmap *regmap;
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun 	struct gpio_desc *ena_gpiod;
415*4882a593Smuzhiyun };
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun /*
418*4882a593Smuzhiyun  * struct coupling_desc
419*4882a593Smuzhiyun  *
420*4882a593Smuzhiyun  * Describes coupling of regulators. Each regulator should have
421*4882a593Smuzhiyun  * at least a pointer to itself in coupled_rdevs array.
422*4882a593Smuzhiyun  * When a new coupled regulator is resolved, n_resolved is
423*4882a593Smuzhiyun  * incremented.
424*4882a593Smuzhiyun  */
425*4882a593Smuzhiyun struct coupling_desc {
426*4882a593Smuzhiyun 	struct regulator_dev **coupled_rdevs;
427*4882a593Smuzhiyun 	struct regulator_coupler *coupler;
428*4882a593Smuzhiyun 	int n_resolved;
429*4882a593Smuzhiyun 	int n_coupled;
430*4882a593Smuzhiyun };
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun /*
433*4882a593Smuzhiyun  * struct regulator_dev
434*4882a593Smuzhiyun  *
435*4882a593Smuzhiyun  * Voltage / Current regulator class device. One for each
436*4882a593Smuzhiyun  * regulator.
437*4882a593Smuzhiyun  *
438*4882a593Smuzhiyun  * This should *not* be used directly by anything except the regulator
439*4882a593Smuzhiyun  * core and notification injection (which should take the mutex and do
440*4882a593Smuzhiyun  * no other direct access).
441*4882a593Smuzhiyun  */
442*4882a593Smuzhiyun struct regulator_dev {
443*4882a593Smuzhiyun 	const struct regulator_desc *desc;
444*4882a593Smuzhiyun 	int exclusive;
445*4882a593Smuzhiyun 	u32 use_count;
446*4882a593Smuzhiyun 	u32 open_count;
447*4882a593Smuzhiyun 	u32 bypass_count;
448*4882a593Smuzhiyun 
449*4882a593Smuzhiyun 	/* lists we belong to */
450*4882a593Smuzhiyun 	struct list_head list; /* list of all regulators */
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun 	/* lists we own */
453*4882a593Smuzhiyun 	struct list_head consumer_list; /* consumers we supply */
454*4882a593Smuzhiyun 
455*4882a593Smuzhiyun 	struct coupling_desc coupling_desc;
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	struct blocking_notifier_head notifier;
458*4882a593Smuzhiyun 	struct ww_mutex mutex; /* consumer lock */
459*4882a593Smuzhiyun 	struct task_struct *mutex_owner;
460*4882a593Smuzhiyun 	int ref_cnt;
461*4882a593Smuzhiyun 	struct module *owner;
462*4882a593Smuzhiyun 	struct device dev;
463*4882a593Smuzhiyun 	struct regulation_constraints *constraints;
464*4882a593Smuzhiyun 	struct regulator *supply;	/* for tree */
465*4882a593Smuzhiyun 	const char *supply_name;
466*4882a593Smuzhiyun 	struct regmap *regmap;
467*4882a593Smuzhiyun 
468*4882a593Smuzhiyun 	struct delayed_work disable_work;
469*4882a593Smuzhiyun 
470*4882a593Smuzhiyun 	void *reg_data;		/* regulator_dev data */
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun 	struct dentry *debugfs;
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun 	struct regulator_enable_gpio *ena_pin;
475*4882a593Smuzhiyun 	unsigned int ena_gpio_state:1;
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun 	unsigned int is_switch:1;
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun 	/* time when this regulator was disabled last time */
480*4882a593Smuzhiyun 	unsigned long last_off_jiffy;
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
483*4882a593Smuzhiyun };
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun struct regulator_dev *
486*4882a593Smuzhiyun regulator_register(const struct regulator_desc *regulator_desc,
487*4882a593Smuzhiyun 		   const struct regulator_config *config);
488*4882a593Smuzhiyun struct regulator_dev *
489*4882a593Smuzhiyun devm_regulator_register(struct device *dev,
490*4882a593Smuzhiyun 			const struct regulator_desc *regulator_desc,
491*4882a593Smuzhiyun 			const struct regulator_config *config);
492*4882a593Smuzhiyun void regulator_unregister(struct regulator_dev *rdev);
493*4882a593Smuzhiyun void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev);
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun int regulator_notifier_call_chain(struct regulator_dev *rdev,
496*4882a593Smuzhiyun 				  unsigned long event, void *data);
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun void *rdev_get_drvdata(struct regulator_dev *rdev);
499*4882a593Smuzhiyun struct device *rdev_get_dev(struct regulator_dev *rdev);
500*4882a593Smuzhiyun struct regmap *rdev_get_regmap(struct regulator_dev *rdev);
501*4882a593Smuzhiyun int rdev_get_id(struct regulator_dev *rdev);
502*4882a593Smuzhiyun 
503*4882a593Smuzhiyun int regulator_mode_to_status(unsigned int);
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun int regulator_list_voltage_linear(struct regulator_dev *rdev,
506*4882a593Smuzhiyun 				  unsigned int selector);
507*4882a593Smuzhiyun int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
508*4882a593Smuzhiyun 						   unsigned int selector);
509*4882a593Smuzhiyun int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
510*4882a593Smuzhiyun 					unsigned int selector);
511*4882a593Smuzhiyun int regulator_list_voltage_table(struct regulator_dev *rdev,
512*4882a593Smuzhiyun 				  unsigned int selector);
513*4882a593Smuzhiyun int regulator_map_voltage_linear(struct regulator_dev *rdev,
514*4882a593Smuzhiyun 				  int min_uV, int max_uV);
515*4882a593Smuzhiyun int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
516*4882a593Smuzhiyun 						  int min_uV, int max_uV);
517*4882a593Smuzhiyun int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
518*4882a593Smuzhiyun 				       int min_uV, int max_uV);
519*4882a593Smuzhiyun int regulator_map_voltage_iterate(struct regulator_dev *rdev,
520*4882a593Smuzhiyun 				  int min_uV, int max_uV);
521*4882a593Smuzhiyun int regulator_map_voltage_ascend(struct regulator_dev *rdev,
522*4882a593Smuzhiyun 				  int min_uV, int max_uV);
523*4882a593Smuzhiyun int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev);
524*4882a593Smuzhiyun int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
525*4882a593Smuzhiyun 						unsigned int sel);
526*4882a593Smuzhiyun int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
527*4882a593Smuzhiyun int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
528*4882a593Smuzhiyun int regulator_is_enabled_regmap(struct regulator_dev *rdev);
529*4882a593Smuzhiyun int regulator_enable_regmap(struct regulator_dev *rdev);
530*4882a593Smuzhiyun int regulator_disable_regmap(struct regulator_dev *rdev);
531*4882a593Smuzhiyun int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
532*4882a593Smuzhiyun 				   unsigned int old_selector,
533*4882a593Smuzhiyun 				   unsigned int new_selector);
534*4882a593Smuzhiyun int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
535*4882a593Smuzhiyun int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
536*4882a593Smuzhiyun int regulator_set_soft_start_regmap(struct regulator_dev *rdev);
537*4882a593Smuzhiyun int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
540*4882a593Smuzhiyun 					  bool enable);
541*4882a593Smuzhiyun int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
542*4882a593Smuzhiyun 				       int min_uA, int max_uA);
543*4882a593Smuzhiyun int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
544*4882a593Smuzhiyun void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
545*4882a593Smuzhiyun 
546*4882a593Smuzhiyun /*
547*4882a593Smuzhiyun  * Helper functions intended to be used by regulator drivers prior registering
548*4882a593Smuzhiyun  * their regulators.
549*4882a593Smuzhiyun  */
550*4882a593Smuzhiyun int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
551*4882a593Smuzhiyun 					     unsigned int selector);
552*4882a593Smuzhiyun 
553*4882a593Smuzhiyun #endif
554