xref: /linux-6.15/include/linux/regulator/driver.h (revision 42d7c87b)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2571a354bSLiam Girdwood /*
3571a354bSLiam Girdwood  * driver.h -- SoC Regulator driver support.
4571a354bSLiam Girdwood  *
5571a354bSLiam Girdwood  * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC.
6571a354bSLiam Girdwood  *
71dd68f01SLiam Girdwood  * Author: Liam Girdwood <[email protected]>
8571a354bSLiam Girdwood  *
9571a354bSLiam Girdwood  * Regulator Driver Interface.
10571a354bSLiam Girdwood  */
11571a354bSLiam Girdwood 
12571a354bSLiam Girdwood #ifndef __LINUX_REGULATOR_DRIVER_H_
13571a354bSLiam Girdwood #define __LINUX_REGULATOR_DRIVER_H_
14571a354bSLiam Girdwood 
15571a354bSLiam Girdwood #include <linux/device.h>
1660ab7f41SMatti Vaittinen #include <linux/linear_range.h>
17ced55d4eSPaul Gortmaker #include <linux/notifier.h>
18571a354bSLiam Girdwood #include <linux/regulator/consumer.h>
19f8702f9eSDmitry Osipenko #include <linux/ww_mutex.h>
20571a354bSLiam Girdwood 
21e45e290aSLinus Walleij struct gpio_desc;
2265b19ce6SMark Brown struct regmap;
23571a354bSLiam Girdwood struct regulator_dev;
24bfa21a0dSKrzysztof Kozlowski struct regulator_config;
25a5766f11SLiam Girdwood struct regulator_init_data;
26f19b00daSKim, Milo struct regulator_enable_gpio;
27571a354bSLiam Girdwood 
28853116a1SDavid Brownell enum regulator_status {
29853116a1SDavid Brownell 	REGULATOR_STATUS_OFF,
30853116a1SDavid Brownell 	REGULATOR_STATUS_ON,
31853116a1SDavid Brownell 	REGULATOR_STATUS_ERROR,
32853116a1SDavid Brownell 	/* fast/normal/idle/standby are flavors of "on" */
33853116a1SDavid Brownell 	REGULATOR_STATUS_FAST,
34853116a1SDavid Brownell 	REGULATOR_STATUS_NORMAL,
35853116a1SDavid Brownell 	REGULATOR_STATUS_IDLE,
36853116a1SDavid Brownell 	REGULATOR_STATUS_STANDBY,
37f59c8f9fSMark Brown 	/* The regulator is enabled but not regulating */
38f59c8f9fSMark Brown 	REGULATOR_STATUS_BYPASS,
391beaf762SKrystian Garbaciak 	/* in case that any other status doesn't apply */
401beaf762SKrystian Garbaciak 	REGULATOR_STATUS_UNDEFINED,
41853116a1SDavid Brownell };
42853116a1SDavid Brownell 
4389a6a5e5SMatti Vaittinen enum regulator_detection_severity {
4489a6a5e5SMatti Vaittinen 	/* Hardware shut down voltage outputs if condition is detected */
4589a6a5e5SMatti Vaittinen 	REGULATOR_SEVERITY_PROT,
4689a6a5e5SMatti Vaittinen 	/* Hardware is probably damaged/inoperable */
4789a6a5e5SMatti Vaittinen 	REGULATOR_SEVERITY_ERR,
4889a6a5e5SMatti Vaittinen 	/* Hardware is still recoverable but recovery action must be taken */
4989a6a5e5SMatti Vaittinen 	REGULATOR_SEVERITY_WARN,
5089a6a5e5SMatti Vaittinen };
5189a6a5e5SMatti Vaittinen 
5260ab7f41SMatti Vaittinen /* Initialize struct linear_range for regulators */
538828bae4SAxel Lin #define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV)	\
5467ba055dSAndy Shevchenko 	LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV)
558828bae4SAxel Lin 
5694d33c02SMark Brown /**
57571a354bSLiam Girdwood  * struct regulator_ops - regulator operations.
58571a354bSLiam Girdwood  *
593b2a6061SDavid Brownell  * @enable: Configure the regulator as enabled.
603b2a6061SDavid Brownell  * @disable: Configure the regulator as disabled.
61d87b969dSWolfram Sang  * @is_enabled: Return 1 if the regulator is enabled, 0 if not.
62d87b969dSWolfram Sang  *		May also return negative errno.
63c8e7e464SMark Brown  *
64c8e7e464SMark Brown  * @set_voltage: Set the voltage for the regulator within the range specified.
65c8e7e464SMark Brown  *               The driver should select the voltage closest to min_uV.
66e8eef82bSMark Brown  * @set_voltage_sel: Set the voltage for the regulator using the specified
67e8eef82bSMark Brown  *                   selector.
68e843fc46SMark Brown  * @map_voltage: Convert a voltage into a selector
6984b3a7c9SDouglas Anderson  * @get_voltage: Return the currently configured voltage for the regulator;
7084b3a7c9SDouglas Anderson  *                   return -ENOTRECOVERABLE if regulator can't be read at
7184b3a7c9SDouglas Anderson  *                   bootup and hasn't been set yet.
72476c2d83SMark Brown  * @get_voltage_sel: Return the currently configured voltage selector for the
7384b3a7c9SDouglas Anderson  *                   regulator; return -ENOTRECOVERABLE if regulator can't
7484b3a7c9SDouglas Anderson  *                   be read at bootup and hasn't been set yet.
754367cfdcSDavid Brownell  * @list_voltage: Return one of the supported voltages, in microvolts; zero
764367cfdcSDavid Brownell  *	if the selector indicates a voltage that is unusable on this system;
774367cfdcSDavid Brownell  *	or negative errno.  Selectors range from zero to one less than
784367cfdcSDavid Brownell  *	regulator_desc.n_voltages.  Voltages may be reported in any order.
79c8e7e464SMark Brown  *
80c8e7e464SMark Brown  * @set_current_limit: Configure a limit for a current-limited regulator.
8189009e18SAxel Lin  *                     The driver should select the current closest to max_uA.
823b2a6061SDavid Brownell  * @get_current_limit: Get the configured limit for a current-limited regulator.
8336e4f839SStephen Boyd  * @set_input_current_limit: Configure an input limit.
84c8e7e464SMark Brown  *
8589a6a5e5SMatti Vaittinen  * @set_over_current_protection: Support enabling of and setting limits for over
8689a6a5e5SMatti Vaittinen  *	current situation detection. Detection can be configured for three
8789a6a5e5SMatti Vaittinen  *	levels of severity.
888d9f738fSYanteng Si  *
898d9f738fSYanteng Si  *	- REGULATOR_SEVERITY_PROT should automatically shut down the regulator(s).
908d9f738fSYanteng Si  *
918d9f738fSYanteng Si  *	- REGULATOR_SEVERITY_ERR should indicate that over-current situation is
9289a6a5e5SMatti Vaittinen  *		  caused by an unrecoverable error but HW does not perform
9389a6a5e5SMatti Vaittinen  *		  automatic shut down.
948d9f738fSYanteng Si  *
958d9f738fSYanteng Si  *	- REGULATOR_SEVERITY_WARN should indicate situation where hardware is
9689a6a5e5SMatti Vaittinen  *		  still believed to not be damaged but that a board sepcific
9789a6a5e5SMatti Vaittinen  *		  recovery action is needed. If lim_uA is 0 the limit should not
9889a6a5e5SMatti Vaittinen  *		  be changed but the detection should just be enabled/disabled as
9989a6a5e5SMatti Vaittinen  *		  is requested.
1008d9f738fSYanteng Si  *
10189a6a5e5SMatti Vaittinen  * @set_over_voltage_protection: Support enabling of and setting limits for over
10289a6a5e5SMatti Vaittinen  *	voltage situation detection. Detection can be configured for same
10392b13482SMatti Vaittinen  *	severities as over current protection. Units of uV.
10489a6a5e5SMatti Vaittinen  * @set_under_voltage_protection: Support enabling of and setting limits for
10592b13482SMatti Vaittinen  *	under voltage situation detection. Detection can be configured for same
10692b13482SMatti Vaittinen  *	severities as over current protection. Units of uV.
10789a6a5e5SMatti Vaittinen  * @set_thermal_protection: Support enabling of and setting limits for over
10892b13482SMatti Vaittinen  *	temperature situation detection.Detection can be configured for same
10992b13482SMatti Vaittinen  *	severities as over current protection. Units of degree Kelvin.
110abf2f825SLuis de Bethencourt  *
111670666b9SLaxman Dewangan  * @set_active_discharge: Set active discharge enable/disable of regulators.
112670666b9SLaxman Dewangan  *
1139f653251SRandy Dunlap  * @set_mode: Set the configured operating mode for the regulator.
1143b2a6061SDavid Brownell  * @get_mode: Get the configured operating mode for the regulator.
1151b5b4221SAxel Haslam  * @get_error_flags: Get the current error(s) for the regulator.
1163b2a6061SDavid Brownell  * @get_status: Return actual (not as-configured) status of regulator, as a
1173b2a6061SDavid Brownell  *	REGULATOR_STATUS value (or negative errno)
118c8e7e464SMark Brown  * @get_optimum_mode: Get the most efficient operating mode for the regulator
119c8e7e464SMark Brown  *                    when running with the specified parameters.
1208f4490e0SBjorn Andersson  * @set_load: Set the load for the regulator.
121c8e7e464SMark Brown  *
122f59c8f9fSMark Brown  * @set_bypass: Set the regulator in bypass mode.
123f59c8f9fSMark Brown  * @get_bypass: Get the regulator bypass mode state.
124f59c8f9fSMark Brown  *
12531aae2beSMark Brown  * @enable_time: Time taken for the regulator voltage output voltage to
12677af1b26SLinus Walleij  *               stabilise after being enabled, in microseconds.
1276f0b2c69SYadwinder Singh Brar  * @set_ramp_delay: Set the ramp delay for the regulator. The driver should
1286f0b2c69SYadwinder Singh Brar  *		select ramp delay equal to or less than(closest) ramp_delay.
12973e705bfSMatthias Kaehlcke  * @set_voltage_time: Time taken for the regulator voltage output voltage
13073e705bfSMatthias Kaehlcke  *               to stabilise after being set to a new value, in microseconds.
13173e705bfSMatthias Kaehlcke  *               The function receives the from and to voltage as input, it
13273e705bfSMatthias Kaehlcke  *               should return the worst case.
13377af1b26SLinus Walleij  * @set_voltage_time_sel: Time taken for the regulator voltage output voltage
13477af1b26SLinus Walleij  *               to stabilise after being set to a new value, in microseconds.
13573e705bfSMatthias Kaehlcke  *               The function receives the from and to voltage selector as
13673e705bfSMatthias Kaehlcke  *               input, it should return the worst case.
137c751ad0dSStephen Boyd  * @set_soft_start: Enable soft start for the regulator.
13831aae2beSMark Brown  *
139c8e7e464SMark Brown  * @set_suspend_voltage: Set the voltage for the regulator when the system
140c8e7e464SMark Brown  *                       is suspended.
141c8e7e464SMark Brown  * @set_suspend_enable: Mark the regulator as enabled when the system is
142c8e7e464SMark Brown  *                      suspended.
143c8e7e464SMark Brown  * @set_suspend_disable: Mark the regulator as disabled when the system is
144c8e7e464SMark Brown  *                       suspended.
145c8e7e464SMark Brown  * @set_suspend_mode: Set the operating mode for the regulator when the
146c8e7e464SMark Brown  *                    system is suspended.
147a98bcaa9SColton Lewis  * @resume: Resume operation of suspended regulator.
14823c779b9SStephen Boyd  * @set_pull_down: Configure the regulator to pull down when the regulator
14923c779b9SStephen Boyd  *		   is disabled.
15023c779b9SStephen Boyd  *
1513b2a6061SDavid Brownell  * This struct describes regulator operations which can be implemented by
1523b2a6061SDavid Brownell  * regulator chip drivers.
153571a354bSLiam Girdwood  */
154571a354bSLiam Girdwood struct regulator_ops {
155571a354bSLiam Girdwood 
1564367cfdcSDavid Brownell 	/* enumerate supported voltages */
1574367cfdcSDavid Brownell 	int (*list_voltage) (struct regulator_dev *, unsigned selector);
1584367cfdcSDavid Brownell 
159571a354bSLiam Girdwood 	/* get/set regulator voltage */
1603a93f2a9SMark Brown 	int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
1613a93f2a9SMark Brown 			    unsigned *selector);
162e843fc46SMark Brown 	int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV);
163e8eef82bSMark Brown 	int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
164571a354bSLiam Girdwood 	int (*get_voltage) (struct regulator_dev *);
165476c2d83SMark Brown 	int (*get_voltage_sel) (struct regulator_dev *);
166571a354bSLiam Girdwood 
167571a354bSLiam Girdwood 	/* get/set regulator current  */
168571a354bSLiam Girdwood 	int (*set_current_limit) (struct regulator_dev *,
169571a354bSLiam Girdwood 				 int min_uA, int max_uA);
170571a354bSLiam Girdwood 	int (*get_current_limit) (struct regulator_dev *);
171571a354bSLiam Girdwood 
17236e4f839SStephen Boyd 	int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
17389a6a5e5SMatti Vaittinen 	int (*set_over_current_protection)(struct regulator_dev *, int lim_uA,
17489a6a5e5SMatti Vaittinen 					   int severity, bool enable);
17589a6a5e5SMatti Vaittinen 	int (*set_over_voltage_protection)(struct regulator_dev *, int lim_uV,
17689a6a5e5SMatti Vaittinen 					   int severity, bool enable);
17789a6a5e5SMatti Vaittinen 	int (*set_under_voltage_protection)(struct regulator_dev *, int lim_uV,
17889a6a5e5SMatti Vaittinen 					    int severity, bool enable);
17989a6a5e5SMatti Vaittinen 	int (*set_thermal_protection)(struct regulator_dev *, int lim,
18089a6a5e5SMatti Vaittinen 				      int severity, bool enable);
181670666b9SLaxman Dewangan 	int (*set_active_discharge)(struct regulator_dev *, bool enable);
18236e4f839SStephen Boyd 
183571a354bSLiam Girdwood 	/* enable/disable regulator */
184571a354bSLiam Girdwood 	int (*enable) (struct regulator_dev *);
185571a354bSLiam Girdwood 	int (*disable) (struct regulator_dev *);
186571a354bSLiam Girdwood 	int (*is_enabled) (struct regulator_dev *);
187571a354bSLiam Girdwood 
188fde297bbSKim, Milo 	/* get/set regulator operating mode (defined in consumer.h) */
189571a354bSLiam Girdwood 	int (*set_mode) (struct regulator_dev *, unsigned int mode);
190571a354bSLiam Girdwood 	unsigned int (*get_mode) (struct regulator_dev *);
191571a354bSLiam Girdwood 
1921b5b4221SAxel Haslam 	/* retrieve current error flags on the regulator */
1931b5b4221SAxel Haslam 	int (*get_error_flags)(struct regulator_dev *, unsigned int *flags);
1941b5b4221SAxel Haslam 
19577af1b26SLinus Walleij 	/* Time taken to enable or set voltage on the regulator */
19631aae2beSMark Brown 	int (*enable_time) (struct regulator_dev *);
1976f0b2c69SYadwinder Singh Brar 	int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay);
19873e705bfSMatthias Kaehlcke 	int (*set_voltage_time) (struct regulator_dev *, int old_uV,
19973e705bfSMatthias Kaehlcke 				 int new_uV);
20077af1b26SLinus Walleij 	int (*set_voltage_time_sel) (struct regulator_dev *,
20177af1b26SLinus Walleij 				     unsigned int old_selector,
20277af1b26SLinus Walleij 				     unsigned int new_selector);
20331aae2beSMark Brown 
20457f66b78SStephen Boyd 	int (*set_soft_start) (struct regulator_dev *);
20557f66b78SStephen Boyd 
206853116a1SDavid Brownell 	/* report regulator status ... most other accessors report
207853116a1SDavid Brownell 	 * control inputs, this reports results of combining inputs
208853116a1SDavid Brownell 	 * from Linux (and other sources) with the actual load.
2093b2a6061SDavid Brownell 	 * returns REGULATOR_STATUS_* or negative errno.
210853116a1SDavid Brownell 	 */
211853116a1SDavid Brownell 	int (*get_status)(struct regulator_dev *);
212853116a1SDavid Brownell 
213571a354bSLiam Girdwood 	/* get most efficient regulator operating mode for load */
214571a354bSLiam Girdwood 	unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV,
215571a354bSLiam Girdwood 					  int output_uV, int load_uA);
2168f4490e0SBjorn Andersson 	/* set the load on the regulator */
2178f4490e0SBjorn Andersson 	int (*set_load)(struct regulator_dev *, int load_uA);
218571a354bSLiam Girdwood 
219f59c8f9fSMark Brown 	/* control and report on bypass mode */
220f59c8f9fSMark Brown 	int (*set_bypass)(struct regulator_dev *dev, bool enable);
221f59c8f9fSMark Brown 	int (*get_bypass)(struct regulator_dev *dev, bool *enable);
222f59c8f9fSMark Brown 
223571a354bSLiam Girdwood 	/* the operations below are for configuration of regulator state when
2243de89609SMark Brown 	 * its parent PMIC enters a global STANDBY/HIBERNATE state */
225571a354bSLiam Girdwood 
226571a354bSLiam Girdwood 	/* set regulator suspend voltage */
227571a354bSLiam Girdwood 	int (*set_suspend_voltage) (struct regulator_dev *, int uV);
228571a354bSLiam Girdwood 
229571a354bSLiam Girdwood 	/* enable/disable regulator in suspend state */
230571a354bSLiam Girdwood 	int (*set_suspend_enable) (struct regulator_dev *);
231571a354bSLiam Girdwood 	int (*set_suspend_disable) (struct regulator_dev *);
232571a354bSLiam Girdwood 
233fde297bbSKim, Milo 	/* set regulator suspend operating mode (defined in consumer.h) */
234571a354bSLiam Girdwood 	int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
23523c779b9SStephen Boyd 
2360380cf7dSpascal paillet 	int (*resume)(struct regulator_dev *rdev);
237f7efad10SChunyan Zhang 
23823c779b9SStephen Boyd 	int (*set_pull_down) (struct regulator_dev *);
239571a354bSLiam Girdwood };
240571a354bSLiam Girdwood 
241571a354bSLiam Girdwood /*
242571a354bSLiam Girdwood  * Regulators can either control voltage or current.
243571a354bSLiam Girdwood  */
244571a354bSLiam Girdwood enum regulator_type {
245571a354bSLiam Girdwood 	REGULATOR_VOLTAGE,
246571a354bSLiam Girdwood 	REGULATOR_CURRENT,
247571a354bSLiam Girdwood };
248571a354bSLiam Girdwood 
249571a354bSLiam Girdwood /**
250c172708dSMark Brown  * struct regulator_desc - Static regulator descriptor
251571a354bSLiam Girdwood  *
252c172708dSMark Brown  * Each regulator registered with the core is described with a
253c172708dSMark Brown  * structure of this type and a struct regulator_config.  This
254c172708dSMark Brown  * structure contains the non-varying parts of the regulator
255c172708dSMark Brown  * description.
256c8e7e464SMark Brown  *
257c8e7e464SMark Brown  * @name: Identifying name for the regulator.
25869511a45SRajendra Nayak  * @supply_name: Identifying the regulator supply
259a0c7b164SMark Brown  * @of_match: Name used to identify regulator in DT.
260e7095c35SCristian Marussi  * @of_match_full_name: A flag to indicate that the of_match string, if
261e7095c35SCristian Marussi  *			present, should be matched against the node full_name.
262a0c7b164SMark Brown  * @regulators_node: Name of node containing regulator definitions in DT.
263bfa21a0dSKrzysztof Kozlowski  * @of_parse_cb: Optional callback called only if of_match is present.
264bfa21a0dSKrzysztof Kozlowski  *               Will be called for each regulator parsed from DT, during
265bfa21a0dSKrzysztof Kozlowski  *               init_data parsing.
266bfa21a0dSKrzysztof Kozlowski  *               The regulator_config passed as argument to the callback will
267bfa21a0dSKrzysztof Kozlowski  *               be a copy of config passed to regulator_register, valid only
268bfa21a0dSKrzysztof Kozlowski  *               for this particular call. Callback may freely change the
269bfa21a0dSKrzysztof Kozlowski  *               config but it cannot store it for later usage.
270bfa21a0dSKrzysztof Kozlowski  *               Callback should return 0 on success or negative ERRNO
271bfa21a0dSKrzysztof Kozlowski  *               indicating failure.
272e55f45b0SJerome Brunet  * @init_cb: Optional callback called after the parsing of init_data.
273e55f45b0SJerome Brunet  *           Allows the regulator to perform runtime init if necessary,
274e55f45b0SJerome Brunet  *           such as synching the regulator and the parsed constraints.
275e55f45b0SJerome Brunet  *           Callback should return 0 on success or negative ERRNO
276e55f45b0SJerome Brunet  *           indicating failure.
277c8e7e464SMark Brown  * @id: Numerical identifier for the regulator.
278c8e7e464SMark Brown  * @ops: Regulator operations table.
2790ba4887cSRandy Dunlap  * @irq: Interrupt number for the regulator.
280c8e7e464SMark Brown  * @type: Indicates if the regulator is a voltage or current regulator.
281c8e7e464SMark Brown  * @owner: Module providing the regulator, used for refcounting.
282bca7bbffSMark Brown  *
283bd7a2b60SPawel Moll  * @continuous_voltage_range: Indicates if the regulator can set any
284bd7a2b60SPawel Moll  *                            voltage within constrains range.
285bca7bbffSMark Brown  * @n_voltages: Number of selectors available for ops.list_voltage().
286a32e0c77SAxel Lin  * @n_current_limits: Number of selectors available for current limits
287bca7bbffSMark Brown  *
288bca7bbffSMark Brown  * @min_uV: Voltage given by the lowest selector (if linear mapping)
289bca7bbffSMark Brown  * @uV_step: Voltage increase with each selector (if linear mapping)
29033234e79SAxel Lin  * @linear_min_sel: Minimal selector for starting linear mapping
2915a523605SLaxman Dewangan  * @fixed_uV: Fixed voltage of rails.
292ea38d13fSAxel Lin  * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
2935abe4f22SSascha Hauer  * @min_dropout_uV: The minimum dropout voltage this regulator can handle
294a8dbfeedSRandy Dunlap  * @linear_ranges: A constant table of possible voltage ranges.
295269cb04bSChen-Yu Tsai  * @linear_range_selectors_bitfield: A constant table of voltage range
296269cb04bSChen-Yu Tsai  *                                   selectors as bitfield values. If
297269cb04bSChen-Yu Tsai  *                                   pickable ranges are used each range
298269cb04bSChen-Yu Tsai  *                                   must have corresponding selector here.
29918e4b55fSMatti Vaittinen  * @n_linear_ranges: Number of entries in the @linear_ranges (and in
300269cb04bSChen-Yu Tsai  *		     linear_range_selectors_bitfield if used) table(s).
301cffc9592SAxel Lin  * @volt_table: Voltage mapping table (if table based mapping)
302a32e0c77SAxel Lin  * @curr_table: Current limit mapping table (if table based mapping)
303bca7bbffSMark Brown  *
30418e4b55fSMatti Vaittinen  * @vsel_range_reg: Register for range selector when using pickable ranges
305bd3ebed9SMauro Carvalho Chehab  *		    and ``regulator_map_*_voltage_*_pickable`` functions.
30618e4b55fSMatti Vaittinen  * @vsel_range_mask: Mask for register bitfield used for range selector
307f4f4276fSMatti Vaittinen  * @range_applied_by_vsel: A flag to indicate that changes to vsel_range_reg
308f4f4276fSMatti Vaittinen  *			   are only effective after vsel_reg is written
309bd3ebed9SMauro Carvalho Chehab  * @vsel_reg: Register for selector when using ``regulator_map_*_voltage_*``
3104ab5b3d9SMark Brown  * @vsel_mask: Mask for register bitfield used for selector
3112da8d947SBartosz Golaszewski  * @vsel_step: Specify the resolution of selector stepping when setting
3122da8d947SBartosz Golaszewski  *	       voltage. If 0, then no stepping is done (requested selector is
3132da8d947SBartosz Golaszewski  *	       set directly), if >0 then the regulator API will ramp the
3142da8d947SBartosz Golaszewski  *	       voltage up/down gradually each time increasing/decreasing the
3152da8d947SBartosz Golaszewski  *	       selector by the specified step value.
31635d838ffSAxel Lin  * @csel_reg: Register for current limit selector using regmap set_current_limit
31735d838ffSAxel Lin  * @csel_mask: Mask for register bitfield used for current limit selector
318c8520b4cSAxel Lin  * @apply_reg: Register for initiate voltage change on the output when
319c8520b4cSAxel Lin  *                using regulator_set_voltage_sel_regmap
320c8520b4cSAxel Lin  * @apply_bit: Register bitfield used for initiate voltage change on the
321c8520b4cSAxel Lin  *                output when using regulator_set_voltage_sel_regmap
322cd6dffb4SMark Brown  * @enable_reg: Register for control when using regmap enable/disable ops
323cd6dffb4SMark Brown  * @enable_mask: Mask for control when using regmap enable/disable ops
324ca5d1b35SCarlo Caione  * @enable_val: Enabling value for control when using regmap enable/disable ops
325ca5d1b35SCarlo Caione  * @disable_val: Disabling value for control when using regmap enable/disable ops
32651dcdafcSAxel Lin  * @enable_is_inverted: A flag to indicate set enable_mask bits to disable
32751dcdafcSAxel Lin  *                      when using regulator_enable_regmap and friends APIs.
3285838b032SNishanth Menon  * @bypass_reg: Register for control when using regmap set_bypass
3295838b032SNishanth Menon  * @bypass_mask: Mask for control when using regmap set_bypass
330ca5d1b35SCarlo Caione  * @bypass_val_on: Enabling value for control when using regmap set_bypass
331ca5d1b35SCarlo Caione  * @bypass_val_off: Disabling value for control when using regmap set_bypass
332354794daSLaxman Dewangan  * @active_discharge_off: Enabling value for control when using regmap
333354794daSLaxman Dewangan  *			  set_active_discharge
334354794daSLaxman Dewangan  * @active_discharge_on: Disabling value for control when using regmap
335354794daSLaxman Dewangan  *			 set_active_discharge
336354794daSLaxman Dewangan  * @active_discharge_mask: Mask for control when using regmap
337354794daSLaxman Dewangan  *			   set_active_discharge
338354794daSLaxman Dewangan  * @active_discharge_reg: Register for control when using regmap
339354794daSLaxman Dewangan  *			  set_active_discharge
340a7a453f5SCharles Keepax  * @soft_start_reg: Register for control when using regmap set_soft_start
341a7a453f5SCharles Keepax  * @soft_start_mask: Mask for control when using regmap set_soft_start
342a7a453f5SCharles Keepax  * @soft_start_val_on: Enabling value for control when using regmap
343a7a453f5SCharles Keepax  *                     set_soft_start
344f7d37bc3SCharles Keepax  * @pull_down_reg: Register for control when using regmap set_pull_down
345f7d37bc3SCharles Keepax  * @pull_down_mask: Mask for control when using regmap set_pull_down
346f7d37bc3SCharles Keepax  * @pull_down_val_on: Enabling value for control when using regmap
347f7d37bc3SCharles Keepax  *                     set_pull_down
34879511ed3SMark Brown  *
349c049742fSMatti Vaittinen  * @ramp_reg:		Register for controlling the regulator ramp-rate.
350c049742fSMatti Vaittinen  * @ramp_mask:		Bitmask for the ramp-rate control register.
351c049742fSMatti Vaittinen  * @ramp_delay_table:	Table for mapping the regulator ramp-rate values. Values
352c049742fSMatti Vaittinen  *			should be given in units of V/S (uV/uS). See the
353c049742fSMatti Vaittinen  *			regulator_set_ramp_delay_regmap().
3540e584d46SMauro Carvalho Chehab  * @n_ramp_values:	number of elements at @ramp_delay_table.
355c049742fSMatti Vaittinen  *
35679511ed3SMark Brown  * @enable_time: Time taken for initial enable of regulator (in uS).
357871f5650SGuodong Xu  * @off_on_delay: guard time (in uS), before re-enabling a regulator
35887e1e0f2SJavier Martinez Canillas  *
359f7d7ad42SSumit Semwal  * @poll_enabled_time: The polling interval (in uS) to use while checking that
360f7d7ad42SSumit Semwal  *                     the regulator was actually enabled. Max upto enable_time.
361f7d7ad42SSumit Semwal  *
36287e1e0f2SJavier Martinez Canillas  * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
363571a354bSLiam Girdwood  */
364571a354bSLiam Girdwood struct regulator_desc {
365571a354bSLiam Girdwood 	const char *name;
36669511a45SRajendra Nayak 	const char *supply_name;
367a0c7b164SMark Brown 	const char *of_match;
368e7095c35SCristian Marussi 	bool of_match_full_name;
369a0c7b164SMark Brown 	const char *regulators_node;
370bfa21a0dSKrzysztof Kozlowski 	int (*of_parse_cb)(struct device_node *,
371bfa21a0dSKrzysztof Kozlowski 			    const struct regulator_desc *,
372bfa21a0dSKrzysztof Kozlowski 			    struct regulator_config *);
373cfcdf395SJerome Brunet 	int (*init_cb)(struct regulator_dev *,
374cfcdf395SJerome Brunet 		       struct regulator_config *);
375571a354bSLiam Girdwood 	int id;
376de4a54c4SMark Brown 	unsigned int continuous_voltage_range:1;
3774367cfdcSDavid Brownell 	unsigned n_voltages;
378a32e0c77SAxel Lin 	unsigned int n_current_limits;
379df11e506SAxel Lin 	const struct regulator_ops *ops;
380571a354bSLiam Girdwood 	int irq;
381571a354bSLiam Girdwood 	enum regulator_type type;
382571a354bSLiam Girdwood 	struct module *owner;
3834ab5b3d9SMark Brown 
384bca7bbffSMark Brown 	unsigned int min_uV;
385bca7bbffSMark Brown 	unsigned int uV_step;
38633234e79SAxel Lin 	unsigned int linear_min_sel;
3875a523605SLaxman Dewangan 	int fixed_uV;
38898a175b6SYadwinder Singh Brar 	unsigned int ramp_delay;
3895abe4f22SSascha Hauer 	int min_dropout_uV;
390bca7bbffSMark Brown 
39160ab7f41SMatti Vaittinen 	const struct linear_range *linear_ranges;
392269cb04bSChen-Yu Tsai 	const unsigned int *linear_range_selectors_bitfield;
39318e4b55fSMatti Vaittinen 
39494d33c02SMark Brown 	int n_linear_ranges;
39594d33c02SMark Brown 
396cffc9592SAxel Lin 	const unsigned int *volt_table;
397a32e0c77SAxel Lin 	const unsigned int *curr_table;
398cffc9592SAxel Lin 
39918e4b55fSMatti Vaittinen 	unsigned int vsel_range_reg;
40018e4b55fSMatti Vaittinen 	unsigned int vsel_range_mask;
401f4f4276fSMatti Vaittinen 	bool range_applied_by_vsel;
4024ab5b3d9SMark Brown 	unsigned int vsel_reg;
4034ab5b3d9SMark Brown 	unsigned int vsel_mask;
4042da8d947SBartosz Golaszewski 	unsigned int vsel_step;
405c0ea88b8SNikita Kiryanov 	unsigned int csel_reg;
406c0ea88b8SNikita Kiryanov 	unsigned int csel_mask;
407c8520b4cSAxel Lin 	unsigned int apply_reg;
408c8520b4cSAxel Lin 	unsigned int apply_bit;
409cd6dffb4SMark Brown 	unsigned int enable_reg;
410cd6dffb4SMark Brown 	unsigned int enable_mask;
411ca5d1b35SCarlo Caione 	unsigned int enable_val;
412ca5d1b35SCarlo Caione 	unsigned int disable_val;
41351dcdafcSAxel Lin 	bool enable_is_inverted;
414df367931SMark Brown 	unsigned int bypass_reg;
415df367931SMark Brown 	unsigned int bypass_mask;
416ca5d1b35SCarlo Caione 	unsigned int bypass_val_on;
417ca5d1b35SCarlo Caione 	unsigned int bypass_val_off;
418354794daSLaxman Dewangan 	unsigned int active_discharge_on;
419354794daSLaxman Dewangan 	unsigned int active_discharge_off;
420354794daSLaxman Dewangan 	unsigned int active_discharge_mask;
421354794daSLaxman Dewangan 	unsigned int active_discharge_reg;
422a7a453f5SCharles Keepax 	unsigned int soft_start_reg;
423a7a453f5SCharles Keepax 	unsigned int soft_start_mask;
424a7a453f5SCharles Keepax 	unsigned int soft_start_val_on;
425f7d37bc3SCharles Keepax 	unsigned int pull_down_reg;
426f7d37bc3SCharles Keepax 	unsigned int pull_down_mask;
427f7d37bc3SCharles Keepax 	unsigned int pull_down_val_on;
428fb8fee9eSMatti Vaittinen 	unsigned int ramp_reg;
429fb8fee9eSMatti Vaittinen 	unsigned int ramp_mask;
430fb8fee9eSMatti Vaittinen 	const unsigned int *ramp_delay_table;
431fb8fee9eSMatti Vaittinen 	unsigned int n_ramp_values;
43279511ed3SMark Brown 
43379511ed3SMark Brown 	unsigned int enable_time;
434871f5650SGuodong Xu 
435871f5650SGuodong Xu 	unsigned int off_on_delay;
43687e1e0f2SJavier Martinez Canillas 
437f7d7ad42SSumit Semwal 	unsigned int poll_enabled_time;
438f7d7ad42SSumit Semwal 
43987e1e0f2SJavier Martinez Canillas 	unsigned int (*of_map_mode)(unsigned int mode);
440571a354bSLiam Girdwood };
441571a354bSLiam Girdwood 
442c172708dSMark Brown /**
443c172708dSMark Brown  * struct regulator_config - Dynamic regulator descriptor
444c172708dSMark Brown  *
445c172708dSMark Brown  * Each regulator registered with the core is described with a
446c172708dSMark Brown  * structure of this type and a struct regulator_desc.  This structure
447c172708dSMark Brown  * contains the runtime variable parts of the regulator description.
448c172708dSMark Brown  *
449c172708dSMark Brown  * @dev: struct device for the regulator
450c172708dSMark Brown  * @init_data: platform provided init data, passed through by driver
451c172708dSMark Brown  * @driver_data: private regulator data
452c172708dSMark Brown  * @of_node: OpenFirmware node to parse for device tree bindings (may be
453c172708dSMark Brown  *           NULL).
454cf39284dSAxel Lin  * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
455380a0e6fSMark Brown  *          insufficient.
456541d052dSLinus Walleij  * @ena_gpiod: GPIO controlling regulator enable.
457c172708dSMark Brown  */
458c172708dSMark Brown struct regulator_config {
459c172708dSMark Brown 	struct device *dev;
460c172708dSMark Brown 	const struct regulator_init_data *init_data;
461c172708dSMark Brown 	void *driver_data;
462c172708dSMark Brown 	struct device_node *of_node;
46365b19ce6SMark Brown 	struct regmap *regmap;
46465f73508SMark Brown 
465e45e290aSLinus Walleij 	struct gpio_desc *ena_gpiod;
466c172708dSMark Brown };
467c172708dSMark Brown 
4687111c6d1SMatti Vaittinen /**
4697111c6d1SMatti Vaittinen  * struct regulator_err_state - regulator error/notification status
4707111c6d1SMatti Vaittinen  *
4717111c6d1SMatti Vaittinen  * @rdev:		Regulator which status the struct indicates.
4727111c6d1SMatti Vaittinen  * @notifs:		Events which have occurred on the regulator.
4737111c6d1SMatti Vaittinen  * @errors:		Errors which are active on the regulator.
4747111c6d1SMatti Vaittinen  * @possible_errs:	Errors which can be signaled (by given IRQ).
4757111c6d1SMatti Vaittinen  */
4767111c6d1SMatti Vaittinen struct regulator_err_state {
4777111c6d1SMatti Vaittinen 	struct regulator_dev *rdev;
4787111c6d1SMatti Vaittinen 	unsigned long notifs;
4797111c6d1SMatti Vaittinen 	unsigned long errors;
4807111c6d1SMatti Vaittinen 	int possible_errs;
4817111c6d1SMatti Vaittinen };
4827111c6d1SMatti Vaittinen 
4837111c6d1SMatti Vaittinen /**
484c049742fSMatti Vaittinen  * struct regulator_irq_data - regulator error/notification status data
4857111c6d1SMatti Vaittinen  *
4867111c6d1SMatti Vaittinen  * @states:	Status structs for each of the associated regulators.
4877111c6d1SMatti Vaittinen  * @num_states:	Amount of associated regulators.
4887111c6d1SMatti Vaittinen  * @data:	Driver data pointer given at regulator_irq_desc.
4897111c6d1SMatti Vaittinen  * @opaque:	Value storage for IC driver. Core does not update this. ICs
4907111c6d1SMatti Vaittinen  *		may want to store status register value here at map_event and
4917111c6d1SMatti Vaittinen  *		compare contents at 'renable' callback to see if new problems
4927111c6d1SMatti Vaittinen  *		have been added to status. If that is the case it may be
4937111c6d1SMatti Vaittinen  *		desirable to return REGULATOR_ERROR_CLEARED and not
4947111c6d1SMatti Vaittinen  *		REGULATOR_ERROR_ON to allow IRQ fire again and to generate
4957111c6d1SMatti Vaittinen  *		notifications also for the new issues.
4967111c6d1SMatti Vaittinen  *
4977111c6d1SMatti Vaittinen  * This structure is passed to 'map_event' and 'renable' callbacks for
4987111c6d1SMatti Vaittinen  * reporting regulator status to core.
4997111c6d1SMatti Vaittinen  */
5007111c6d1SMatti Vaittinen struct regulator_irq_data {
5017111c6d1SMatti Vaittinen 	struct regulator_err_state *states;
5027111c6d1SMatti Vaittinen 	int num_states;
5037111c6d1SMatti Vaittinen 	void *data;
5047111c6d1SMatti Vaittinen 	long opaque;
5057111c6d1SMatti Vaittinen };
5067111c6d1SMatti Vaittinen 
5077111c6d1SMatti Vaittinen /**
5087111c6d1SMatti Vaittinen  * struct regulator_irq_desc - notification sender for IRQ based events.
5097111c6d1SMatti Vaittinen  *
5107111c6d1SMatti Vaittinen  * @name:	The visible name for the IRQ
5117111c6d1SMatti Vaittinen  * @fatal_cnt:	If this IRQ is used to signal HW damaging condition it may be
5127111c6d1SMatti Vaittinen  *		best to shut-down regulator(s) or reboot the SOC if error
5137111c6d1SMatti Vaittinen  *		handling is repeatedly failing. If fatal_cnt is given the IRQ
5147111c6d1SMatti Vaittinen  *		handling is aborted if it fails for fatal_cnt times and die()
5156966df48SMatti Vaittinen  *		callback (if populated) is called. If die() is not populated
5166966df48SMatti Vaittinen  *		poweroff for the system is attempted in order to prevent any
5177111c6d1SMatti Vaittinen  *		further damage.
5187111c6d1SMatti Vaittinen  * @reread_ms:	The time which is waited before attempting to re-read status
5197111c6d1SMatti Vaittinen  *		at the worker if IC reading fails. Immediate re-read is done
5207111c6d1SMatti Vaittinen  *		if time is not specified.
5217111c6d1SMatti Vaittinen  * @irq_off_ms:	The time which IRQ is kept disabled before re-evaluating the
5227111c6d1SMatti Vaittinen  *		status for devices which keep IRQ disabled for duration of the
5237111c6d1SMatti Vaittinen  *		error. If this is not given the IRQ is left enabled and renable
5247111c6d1SMatti Vaittinen  *		is not called.
5257111c6d1SMatti Vaittinen  * @skip_off:	If set to true the IRQ handler will attempt to check if any of
5267111c6d1SMatti Vaittinen  *		the associated regulators are enabled prior to taking other
5277111c6d1SMatti Vaittinen  *		actions. If no regulators are enabled and this is set to true
5287111c6d1SMatti Vaittinen  *		a spurious IRQ is assumed and IRQ_NONE is returned.
5297111c6d1SMatti Vaittinen  * @high_prio:	Boolean to indicate that high priority WQ should be used.
5307111c6d1SMatti Vaittinen  * @data:	Driver private data pointer which will be passed as such to
5317111c6d1SMatti Vaittinen  *		the renable, map_event and die callbacks in regulator_irq_data.
5327111c6d1SMatti Vaittinen  * @die:	Protection callback. If IC status reading or recovery actions
5336966df48SMatti Vaittinen  *		fail fatal_cnt times this callback is called or system is
5346966df48SMatti Vaittinen  *		powered off. This callback should implement a final protection
5356966df48SMatti Vaittinen  *		attempt like disabling the regulator. If protection succeeded
5366966df48SMatti Vaittinen  *		die() may return 0. If anything else is returned the core
5376966df48SMatti Vaittinen  *		assumes final protection failed and attempts to perform a
5386966df48SMatti Vaittinen  *		poweroff as a last resort.
5397111c6d1SMatti Vaittinen  * @map_event:	Driver callback to map IRQ status into regulator devices with
5407111c6d1SMatti Vaittinen  *		events / errors. NOTE: callback MUST initialize both the
5417111c6d1SMatti Vaittinen  *		errors and notifs for all rdevs which it signals having
5427111c6d1SMatti Vaittinen  *		active events as core does not clean the map data.
5437111c6d1SMatti Vaittinen  *		REGULATOR_FAILED_RETRY can be returned to indicate that the
5447111c6d1SMatti Vaittinen  *		status reading from IC failed. If this is repeated for
545ad3ead1eSMatti Vaittinen  *		fatal_cnt times the core will call die() callback or power-off
546ad3ead1eSMatti Vaittinen  *		the system as a last resort to protect the HW.
5477111c6d1SMatti Vaittinen  * @renable:	Optional callback to check status (if HW supports that) before
5487111c6d1SMatti Vaittinen  *		re-enabling IRQ. If implemented this should clear the error
5497111c6d1SMatti Vaittinen  *		flags so that errors fetched by regulator_get_error_flags()
5507111c6d1SMatti Vaittinen  *		are updated. If callback is not implemented then errors are
5517111c6d1SMatti Vaittinen  *		assumed to be cleared and IRQ is re-enabled.
5527111c6d1SMatti Vaittinen  *		REGULATOR_FAILED_RETRY can be returned to
5537111c6d1SMatti Vaittinen  *		indicate that the status reading from IC failed. If this is
5547111c6d1SMatti Vaittinen  *		repeated for 'fatal_cnt' times the core will call die()
555ad3ead1eSMatti Vaittinen  *		callback or if die() is not populated then attempt to power-off
556ad3ead1eSMatti Vaittinen  *		the system as a last resort to protect the HW.
5577111c6d1SMatti Vaittinen  *		Returning zero indicates that the problem in HW has been solved
5587111c6d1SMatti Vaittinen  *		and IRQ will be re-enabled. Returning REGULATOR_ERROR_ON
5597111c6d1SMatti Vaittinen  *		indicates the error condition is still active and keeps IRQ
5607111c6d1SMatti Vaittinen  *		disabled. Please note that returning REGULATOR_ERROR_ON does
5617111c6d1SMatti Vaittinen  *		not retrigger evaluating what events are active or resending
5627111c6d1SMatti Vaittinen  *		notifications. If this is needed you probably want to return
5637111c6d1SMatti Vaittinen  *		zero and allow IRQ to retrigger causing events to be
5647111c6d1SMatti Vaittinen  *		re-evaluated and re-sent.
5657111c6d1SMatti Vaittinen  *
5667111c6d1SMatti Vaittinen  * This structure is used for registering regulator IRQ notification helper.
5677111c6d1SMatti Vaittinen  */
5687111c6d1SMatti Vaittinen struct regulator_irq_desc {
5697111c6d1SMatti Vaittinen 	const char *name;
5707111c6d1SMatti Vaittinen 	int fatal_cnt;
5717111c6d1SMatti Vaittinen 	int reread_ms;
5727111c6d1SMatti Vaittinen 	int irq_off_ms;
5737111c6d1SMatti Vaittinen 	bool skip_off;
5747111c6d1SMatti Vaittinen 	bool high_prio;
5757111c6d1SMatti Vaittinen 	void *data;
5767111c6d1SMatti Vaittinen 
5777111c6d1SMatti Vaittinen 	int (*die)(struct regulator_irq_data *rid);
5787111c6d1SMatti Vaittinen 	int (*map_event)(int irq, struct regulator_irq_data *rid,
5797111c6d1SMatti Vaittinen 			  unsigned long *dev_mask);
5807111c6d1SMatti Vaittinen 	int (*renable)(struct regulator_irq_data *rid);
5817111c6d1SMatti Vaittinen };
5827111c6d1SMatti Vaittinen 
5837111c6d1SMatti Vaittinen /*
5847111c6d1SMatti Vaittinen  * Return values for regulator IRQ helpers.
5857111c6d1SMatti Vaittinen  */
5867111c6d1SMatti Vaittinen enum {
5877111c6d1SMatti Vaittinen 	REGULATOR_ERROR_CLEARED,
5887111c6d1SMatti Vaittinen 	REGULATOR_FAILED_RETRY,
5897111c6d1SMatti Vaittinen 	REGULATOR_ERROR_ON,
5907111c6d1SMatti Vaittinen };
5917111c6d1SMatti Vaittinen 
5921fa9ad52SMark Brown /*
593a085a31aSMaciej Purski  * struct coupling_desc
594a085a31aSMaciej Purski  *
595a085a31aSMaciej Purski  * Describes coupling of regulators. Each regulator should have
596a085a31aSMaciej Purski  * at least a pointer to itself in coupled_rdevs array.
597a085a31aSMaciej Purski  * When a new coupled regulator is resolved, n_resolved is
598a085a31aSMaciej Purski  * incremented.
599a085a31aSMaciej Purski  */
600a085a31aSMaciej Purski struct coupling_desc {
601d8ca7d18SDmitry Osipenko 	struct regulator_dev **coupled_rdevs;
602d8ca7d18SDmitry Osipenko 	struct regulator_coupler *coupler;
603a085a31aSMaciej Purski 	int n_resolved;
604a085a31aSMaciej Purski 	int n_coupled;
605a085a31aSMaciej Purski };
606a085a31aSMaciej Purski 
607a085a31aSMaciej Purski /*
6081fa9ad52SMark Brown  * struct regulator_dev
6091fa9ad52SMark Brown  *
6101fa9ad52SMark Brown  * Voltage / Current regulator class device. One for each
6111fa9ad52SMark Brown  * regulator.
6121fa9ad52SMark Brown  *
6131fa9ad52SMark Brown  * This should *not* be used directly by anything except the regulator
6141fa9ad52SMark Brown  * core and notification injection (which should take the mutex and do
6151fa9ad52SMark Brown  * no other direct access).
6161fa9ad52SMark Brown  */
6171fa9ad52SMark Brown struct regulator_dev {
61865f26846SMark Brown 	const struct regulator_desc *desc;
6195ffbd136SMark Brown 	int exclusive;
6201130e5b3SMark Brown 	u32 use_count;
6211130e5b3SMark Brown 	u32 open_count;
622f59c8f9fSMark Brown 	u32 bypass_count;
6231fa9ad52SMark Brown 
6241fa9ad52SMark Brown 	/* lists we belong to */
6251fa9ad52SMark Brown 	struct list_head list; /* list of all regulators */
6261fa9ad52SMark Brown 
6271fa9ad52SMark Brown 	/* lists we own */
6281fa9ad52SMark Brown 	struct list_head consumer_list; /* consumers we supply */
6291fa9ad52SMark Brown 
630a085a31aSMaciej Purski 	struct coupling_desc coupling_desc;
631a085a31aSMaciej Purski 
6321fa9ad52SMark Brown 	struct blocking_notifier_head notifier;
633f8702f9eSDmitry Osipenko 	struct ww_mutex mutex; /* consumer lock */
63466cf9a7eSMaciej Purski 	struct task_struct *mutex_owner;
63566cf9a7eSMaciej Purski 	int ref_cnt;
6361fa9ad52SMark Brown 	struct module *owner;
6371fa9ad52SMark Brown 	struct device dev;
6381fa9ad52SMark Brown 	struct regulation_constraints *constraints;
6393801b86aSMark Brown 	struct regulator *supply;	/* for tree */
6406261b06dSBjorn Andersson 	const char *supply_name;
64165b19ce6SMark Brown 	struct regmap *regmap;
6421fa9ad52SMark Brown 
643da07ecd9SMark Brown 	struct delayed_work disable_work;
644da07ecd9SMark Brown 
6451fa9ad52SMark Brown 	void *reg_data;		/* regulator_dev data */
6461130e5b3SMark Brown 
6471130e5b3SMark Brown 	struct dentry *debugfs;
64865f73508SMark Brown 
649f19b00daSKim, Milo 	struct regulator_enable_gpio *ena_pin;
65065f73508SMark Brown 	unsigned int ena_gpio_state:1;
651871f5650SGuodong Xu 
652fd086045SMatthias Kaehlcke 	unsigned int is_switch:1;
653fd086045SMatthias Kaehlcke 
654871f5650SGuodong Xu 	/* time when this regulator was disabled last time */
655a8ce7bd8SVincent Whitchurch 	ktime_t last_off;
6567111c6d1SMatti Vaittinen 	int cached_err;
6577111c6d1SMatti Vaittinen 	bool use_cached_err;
6587111c6d1SMatti Vaittinen 	spinlock_t err_lock;
659*42d7c87bSKory Maincent 
660*42d7c87bSKory Maincent 	int pw_requested_mW;
6611fa9ad52SMark Brown };
6621fa9ad52SMark Brown 
6636fadec4cSMatti Vaittinen /*
6646fadec4cSMatti Vaittinen  * Convert error flags to corresponding notifications.
6656fadec4cSMatti Vaittinen  *
6666fadec4cSMatti Vaittinen  * Can be used by drivers which use the notification helpers to
6676fadec4cSMatti Vaittinen  * find out correct notification flags based on the error flags. Drivers
6686fadec4cSMatti Vaittinen  * can avoid storing both supported notification and error flags which
6696fadec4cSMatti Vaittinen  * may save few bytes.
6706fadec4cSMatti Vaittinen  */
regulator_err2notif(int err)6716fadec4cSMatti Vaittinen static inline int regulator_err2notif(int err)
6726fadec4cSMatti Vaittinen {
6736fadec4cSMatti Vaittinen 	switch (err) {
6746fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_UNDER_VOLTAGE:
6756fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_UNDER_VOLTAGE;
6766fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_OVER_CURRENT:
6776fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_OVER_CURRENT;
6786fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_REGULATION_OUT:
6796fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_REGULATION_OUT;
6806fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_FAIL:
6816fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_FAIL;
6826fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_OVER_TEMP:
6836fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_OVER_TEMP;
6846fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_UNDER_VOLTAGE_WARN:
6856fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_UNDER_VOLTAGE_WARN;
6866fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_OVER_CURRENT_WARN:
6876fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_OVER_CURRENT_WARN;
6886fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_OVER_VOLTAGE_WARN:
6896fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_OVER_VOLTAGE_WARN;
6906fadec4cSMatti Vaittinen 	case REGULATOR_ERROR_OVER_TEMP_WARN:
6916fadec4cSMatti Vaittinen 		return REGULATOR_EVENT_OVER_TEMP_WARN;
6926fadec4cSMatti Vaittinen 	}
6936fadec4cSMatti Vaittinen 	return 0;
6946fadec4cSMatti Vaittinen }
6956fadec4cSMatti Vaittinen 
6966fadec4cSMatti Vaittinen 
69765f26846SMark Brown struct regulator_dev *
6988f3cbcd6SChiYuan Huang regulator_register(struct device *dev,
6998f3cbcd6SChiYuan Huang 		   const struct regulator_desc *regulator_desc,
700c172708dSMark Brown 		   const struct regulator_config *config);
701b33e46bcSMark Brown struct regulator_dev *
702b33e46bcSMark Brown devm_regulator_register(struct device *dev,
703b33e46bcSMark Brown 			const struct regulator_desc *regulator_desc,
704b33e46bcSMark Brown 			const struct regulator_config *config);
705571a354bSLiam Girdwood void regulator_unregister(struct regulator_dev *rdev);
706571a354bSLiam Girdwood 
707571a354bSLiam Girdwood int regulator_notifier_call_chain(struct regulator_dev *rdev,
708571a354bSLiam Girdwood 				  unsigned long event, void *data);
7097111c6d1SMatti Vaittinen void *devm_regulator_irq_helper(struct device *dev,
7107111c6d1SMatti Vaittinen 				const struct regulator_irq_desc *d, int irq,
7117111c6d1SMatti Vaittinen 				int irq_flags, int common_errs,
7127111c6d1SMatti Vaittinen 				int *per_rdev_errs, struct regulator_dev **rdev,
7137111c6d1SMatti Vaittinen 				int rdev_amount);
7147111c6d1SMatti Vaittinen void *regulator_irq_helper(struct device *dev,
7157111c6d1SMatti Vaittinen 			   const struct regulator_irq_desc *d, int irq,
7167111c6d1SMatti Vaittinen 			   int irq_flags, int common_errs, int *per_rdev_errs,
7177111c6d1SMatti Vaittinen 			   struct regulator_dev **rdev, int rdev_amount);
7187111c6d1SMatti Vaittinen void regulator_irq_helper_cancel(void **handle);
719a764ff77SMatti Vaittinen int regulator_irq_map_event_simple(int irq, struct regulator_irq_data *rid,
720a764ff77SMatti Vaittinen 				   unsigned long *dev_mask);
721571a354bSLiam Girdwood 
722571a354bSLiam Girdwood void *rdev_get_drvdata(struct regulator_dev *rdev);
723a5766f11SLiam Girdwood struct device *rdev_get_dev(struct regulator_dev *rdev);
72403c87b95SBartosz Golaszewski struct regmap *rdev_get_regmap(struct regulator_dev *rdev);
725571a354bSLiam Girdwood int rdev_get_id(struct regulator_dev *rdev);
726571a354bSLiam Girdwood 
727be721979SMark Brown int regulator_mode_to_status(unsigned int);
728be721979SMark Brown 
729bca7bbffSMark Brown int regulator_list_voltage_linear(struct regulator_dev *rdev,
730bca7bbffSMark Brown 				  unsigned int selector);
73118e4b55fSMatti Vaittinen int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
73218e4b55fSMatti Vaittinen 						   unsigned int selector);
73394d33c02SMark Brown int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
73494d33c02SMark Brown 					unsigned int selector);
735cffc9592SAxel Lin int regulator_list_voltage_table(struct regulator_dev *rdev,
736cffc9592SAxel Lin 				  unsigned int selector);
737bca7bbffSMark Brown int regulator_map_voltage_linear(struct regulator_dev *rdev,
738bca7bbffSMark Brown 				  int min_uV, int max_uV);
73918e4b55fSMatti Vaittinen int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
74018e4b55fSMatti Vaittinen 						  int min_uV, int max_uV);
74194d33c02SMark Brown int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
74294d33c02SMark Brown 				       int min_uV, int max_uV);
743e843fc46SMark Brown int regulator_map_voltage_iterate(struct regulator_dev *rdev,
744e843fc46SMark Brown 				  int min_uV, int max_uV);
745fcf371eeSAxel Lin int regulator_map_voltage_ascend(struct regulator_dev *rdev,
746fcf371eeSAxel Lin 				  int min_uV, int max_uV);
74718e4b55fSMatti Vaittinen int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev);
74818e4b55fSMatti Vaittinen int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev,
74918e4b55fSMatti Vaittinen 						unsigned int sel);
7504ab5b3d9SMark Brown int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
7514ab5b3d9SMark Brown int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
752cd6dffb4SMark Brown int regulator_is_enabled_regmap(struct regulator_dev *rdev);
753cd6dffb4SMark Brown int regulator_enable_regmap(struct regulator_dev *rdev);
754cd6dffb4SMark Brown int regulator_disable_regmap(struct regulator_dev *rdev);
75598a175b6SYadwinder Singh Brar int regulator_set_voltage_time_sel(struct regulator_dev *rdev,
75698a175b6SYadwinder Singh Brar 				   unsigned int old_selector,
75798a175b6SYadwinder Singh Brar 				   unsigned int new_selector);
758df367931SMark Brown int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable);
759df367931SMark Brown int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable);
760a7a453f5SCharles Keepax int regulator_set_soft_start_regmap(struct regulator_dev *rdev);
761f7d37bc3SCharles Keepax int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
7624ab5b3d9SMark Brown 
763354794daSLaxman Dewangan int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
764354794daSLaxman Dewangan 					  bool enable);
765a32e0c77SAxel Lin int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
766a32e0c77SAxel Lin 				       int min_uA, int max_uA);
767a32e0c77SAxel Lin int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
768a5766f11SLiam Girdwood void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
769431cb97bSSebastian Reichel int regulator_find_closest_bigger(unsigned int target, const unsigned int *table,
770431cb97bSSebastian Reichel 				  unsigned int num_sel, unsigned int *sel);
771fb8fee9eSMatti Vaittinen int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay);
772380d2b2dSDmitry Osipenko int regulator_sync_voltage_rdev(struct regulator_dev *rdev);
773a5766f11SLiam Girdwood 
7746a47b4daSMatti Vaittinen /*
7756a47b4daSMatti Vaittinen  * Helper functions intended to be used by regulator drivers prior registering
7766a47b4daSMatti Vaittinen  * their regulators.
7776a47b4daSMatti Vaittinen  */
7786a47b4daSMatti Vaittinen int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
7796a47b4daSMatti Vaittinen 					     unsigned int selector);
780d8ca7d18SDmitry Osipenko 
781e3baacf5SMatti Vaittinen int regulator_desc_list_voltage_linear(const struct regulator_desc *desc,
782e3baacf5SMatti Vaittinen 				       unsigned int selector);
783157d2230SMatti Vaittinen 
784157d2230SMatti Vaittinen #ifdef CONFIG_REGULATOR
785157d2230SMatti Vaittinen const char *rdev_get_name(struct regulator_dev *rdev);
786157d2230SMatti Vaittinen #else
rdev_get_name(struct regulator_dev * rdev)787157d2230SMatti Vaittinen static inline const char *rdev_get_name(struct regulator_dev *rdev)
788157d2230SMatti Vaittinen {
789157d2230SMatti Vaittinen 	return NULL;
790157d2230SMatti Vaittinen }
791157d2230SMatti Vaittinen #endif
792157d2230SMatti Vaittinen 
793571a354bSLiam Girdwood #endif
794