xref: /OK3568_Linux_fs/kernel/include/linux/regulator/machine.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * machine.h -- SoC Regulator support, machine/board driver API.
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 Machine/Board Interface.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #ifndef __LINUX_REGULATOR_MACHINE_H_
13*4882a593Smuzhiyun #define __LINUX_REGULATOR_MACHINE_H_
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
16*4882a593Smuzhiyun #include <linux/suspend.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun struct regulator;
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun  * Regulator operation constraint flags. These flags are used to enable
22*4882a593Smuzhiyun  * certain regulator operations and can be OR'ed together.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * VOLTAGE:  Regulator output voltage can be changed by software on this
25*4882a593Smuzhiyun  *           board/machine.
26*4882a593Smuzhiyun  * CURRENT:  Regulator output current can be changed by software on this
27*4882a593Smuzhiyun  *           board/machine.
28*4882a593Smuzhiyun  * MODE:     Regulator operating mode can be changed by software on this
29*4882a593Smuzhiyun  *           board/machine.
30*4882a593Smuzhiyun  * STATUS:   Regulator can be enabled and disabled.
31*4882a593Smuzhiyun  * DRMS:     Dynamic Regulator Mode Switching is enabled for this regulator.
32*4882a593Smuzhiyun  * BYPASS:   Regulator can be put into bypass mode
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #define REGULATOR_CHANGE_VOLTAGE	0x1
36*4882a593Smuzhiyun #define REGULATOR_CHANGE_CURRENT	0x2
37*4882a593Smuzhiyun #define REGULATOR_CHANGE_MODE		0x4
38*4882a593Smuzhiyun #define REGULATOR_CHANGE_STATUS		0x8
39*4882a593Smuzhiyun #define REGULATOR_CHANGE_DRMS		0x10
40*4882a593Smuzhiyun #define REGULATOR_CHANGE_BYPASS		0x20
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /*
43*4882a593Smuzhiyun  * operations in suspend mode
44*4882a593Smuzhiyun  * DO_NOTHING_IN_SUSPEND - the default value
45*4882a593Smuzhiyun  * DISABLE_IN_SUSPEND	- turn off regulator in suspend states
46*4882a593Smuzhiyun  * ENABLE_IN_SUSPEND	- keep regulator on in suspend states
47*4882a593Smuzhiyun  */
48*4882a593Smuzhiyun #define DO_NOTHING_IN_SUSPEND	0
49*4882a593Smuzhiyun #define DISABLE_IN_SUSPEND	1
50*4882a593Smuzhiyun #define ENABLE_IN_SUSPEND	2
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /* Regulator active discharge flags */
53*4882a593Smuzhiyun enum regulator_active_discharge {
54*4882a593Smuzhiyun 	REGULATOR_ACTIVE_DISCHARGE_DEFAULT,
55*4882a593Smuzhiyun 	REGULATOR_ACTIVE_DISCHARGE_DISABLE,
56*4882a593Smuzhiyun 	REGULATOR_ACTIVE_DISCHARGE_ENABLE,
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /**
60*4882a593Smuzhiyun  * struct regulator_state - regulator state during low power system states
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  * This describes a regulators state during a system wide low power
63*4882a593Smuzhiyun  * state.  One of enabled or disabled must be set for the
64*4882a593Smuzhiyun  * configuration to be applied.
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  * @uV: Default operating voltage during suspend, it can be adjusted
67*4882a593Smuzhiyun  *	among <min_uV, max_uV>.
68*4882a593Smuzhiyun  * @min_uV: Minimum suspend voltage may be set.
69*4882a593Smuzhiyun  * @max_uV: Maximum suspend voltage may be set.
70*4882a593Smuzhiyun  * @mode: Operating mode during suspend.
71*4882a593Smuzhiyun  * @enabled: operations during suspend.
72*4882a593Smuzhiyun  *	     - DO_NOTHING_IN_SUSPEND
73*4882a593Smuzhiyun  *	     - DISABLE_IN_SUSPEND
74*4882a593Smuzhiyun  *	     - ENABLE_IN_SUSPEND
75*4882a593Smuzhiyun  * @changeable: Is this state can be switched between enabled/disabled,
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun struct regulator_state {
78*4882a593Smuzhiyun 	int uV;
79*4882a593Smuzhiyun 	int min_uV;
80*4882a593Smuzhiyun 	int max_uV;
81*4882a593Smuzhiyun 	unsigned int mode;
82*4882a593Smuzhiyun 	int enabled;
83*4882a593Smuzhiyun 	bool changeable;
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /**
87*4882a593Smuzhiyun  * struct regulation_constraints - regulator operating constraints.
88*4882a593Smuzhiyun  *
89*4882a593Smuzhiyun  * This struct describes regulator and board/machine specific constraints.
90*4882a593Smuzhiyun  *
91*4882a593Smuzhiyun  * @name: Descriptive name for the constraints, used for display purposes.
92*4882a593Smuzhiyun  *
93*4882a593Smuzhiyun  * @min_uV: Smallest voltage consumers may set.
94*4882a593Smuzhiyun  * @max_uV: Largest voltage consumers may set.
95*4882a593Smuzhiyun  * @uV_offset: Offset applied to voltages from consumer to compensate for
96*4882a593Smuzhiyun  *             voltage drops.
97*4882a593Smuzhiyun  *
98*4882a593Smuzhiyun  * @min_uA: Smallest current consumers may set.
99*4882a593Smuzhiyun  * @max_uA: Largest current consumers may set.
100*4882a593Smuzhiyun  * @ilim_uA: Maximum input current.
101*4882a593Smuzhiyun  * @system_load: Load that isn't captured by any consumer requests.
102*4882a593Smuzhiyun  *
103*4882a593Smuzhiyun  * @max_spread: Max possible spread between coupled regulators
104*4882a593Smuzhiyun  * @max_uV_step: Max possible step change in voltage
105*4882a593Smuzhiyun  * @valid_modes_mask: Mask of modes which may be configured by consumers.
106*4882a593Smuzhiyun  * @valid_ops_mask: Operations which may be performed by consumers.
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  * @always_on: Set if the regulator should never be disabled.
109*4882a593Smuzhiyun  * @boot_on: Set if the regulator is enabled when the system is initially
110*4882a593Smuzhiyun  *           started.  If the regulator is not enabled by the hardware or
111*4882a593Smuzhiyun  *           bootloader then it will be enabled when the constraints are
112*4882a593Smuzhiyun  *           applied.
113*4882a593Smuzhiyun  * @apply_uV: Apply the voltage constraint when initialising.
114*4882a593Smuzhiyun  * @ramp_disable: Disable ramp delay when initialising or when setting voltage.
115*4882a593Smuzhiyun  * @soft_start: Enable soft start so that voltage ramps slowly.
116*4882a593Smuzhiyun  * @pull_down: Enable pull down when regulator is disabled.
117*4882a593Smuzhiyun  * @over_current_protection: Auto disable on over current event.
118*4882a593Smuzhiyun  *
119*4882a593Smuzhiyun  * @input_uV: Input voltage for regulator when supplied by another regulator.
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  * @state_disk: State for regulator when system is suspended in disk mode.
122*4882a593Smuzhiyun  * @state_mem: State for regulator when system is suspended in mem mode.
123*4882a593Smuzhiyun  * @state_standby: State for regulator when system is suspended in standby
124*4882a593Smuzhiyun  *                 mode.
125*4882a593Smuzhiyun  * @initial_state: Suspend state to set by default.
126*4882a593Smuzhiyun  * @initial_mode: Mode to set at startup.
127*4882a593Smuzhiyun  * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
128*4882a593Smuzhiyun  * @settling_time: Time to settle down after voltage change when voltage
129*4882a593Smuzhiyun  *		   change is non-linear (unit: microseconds).
130*4882a593Smuzhiyun  * @settling_time_up: Time to settle down after voltage increase when voltage
131*4882a593Smuzhiyun  *		      change is non-linear (unit: microseconds).
132*4882a593Smuzhiyun  * @settling_time_down : Time to settle down after voltage decrease when
133*4882a593Smuzhiyun  *			 voltage change is non-linear (unit: microseconds).
134*4882a593Smuzhiyun  * @active_discharge: Enable/disable active discharge. The enum
135*4882a593Smuzhiyun  *		      regulator_active_discharge values are used for
136*4882a593Smuzhiyun  *		      initialisation.
137*4882a593Smuzhiyun  * @enable_time: Turn-on time of the rails (unit: microseconds)
138*4882a593Smuzhiyun  */
139*4882a593Smuzhiyun struct regulation_constraints {
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	const char *name;
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	/* voltage output range (inclusive) - for voltage control */
144*4882a593Smuzhiyun 	int min_uV;
145*4882a593Smuzhiyun 	int max_uV;
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 	int uV_offset;
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun 	/* current output range (inclusive) - for current control */
150*4882a593Smuzhiyun 	int min_uA;
151*4882a593Smuzhiyun 	int max_uA;
152*4882a593Smuzhiyun 	int ilim_uA;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	int system_load;
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 	/* used for coupled regulators */
157*4882a593Smuzhiyun 	u32 *max_spread;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	/* used for changing voltage in steps */
160*4882a593Smuzhiyun 	int max_uV_step;
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	/* valid regulator operating modes for this machine */
163*4882a593Smuzhiyun 	unsigned int valid_modes_mask;
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	/* valid operations for regulator on this machine */
166*4882a593Smuzhiyun 	unsigned int valid_ops_mask;
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	/* regulator input voltage - only if supply is another regulator */
169*4882a593Smuzhiyun 	int input_uV;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	/* regulator suspend states for global PMIC STANDBY/HIBERNATE */
172*4882a593Smuzhiyun 	struct regulator_state state_disk;
173*4882a593Smuzhiyun 	struct regulator_state state_mem;
174*4882a593Smuzhiyun 	struct regulator_state state_standby;
175*4882a593Smuzhiyun 	suspend_state_t initial_state; /* suspend state to set at init */
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 	/* mode to set on startup */
178*4882a593Smuzhiyun 	unsigned int initial_mode;
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun 	unsigned int ramp_delay;
181*4882a593Smuzhiyun 	unsigned int settling_time;
182*4882a593Smuzhiyun 	unsigned int settling_time_up;
183*4882a593Smuzhiyun 	unsigned int settling_time_down;
184*4882a593Smuzhiyun 	unsigned int enable_time;
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	unsigned int active_discharge;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	/* constraint flags */
189*4882a593Smuzhiyun 	unsigned always_on:1;	/* regulator never off when system is on */
190*4882a593Smuzhiyun 	unsigned boot_on:1;	/* bootloader/firmware enabled regulator */
191*4882a593Smuzhiyun 	unsigned apply_uV:1;	/* apply uV constraint if min == max */
192*4882a593Smuzhiyun 	unsigned ramp_disable:1; /* disable ramp delay */
193*4882a593Smuzhiyun 	unsigned soft_start:1;	/* ramp voltage slowly */
194*4882a593Smuzhiyun 	unsigned pull_down:1;	/* pull down resistor when regulator off */
195*4882a593Smuzhiyun 	unsigned over_current_protection:1; /* auto disable on over current */
196*4882a593Smuzhiyun };
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun /**
199*4882a593Smuzhiyun  * struct regulator_consumer_supply - supply -> device mapping
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * This maps a supply name to a device. Use of dev_name allows support for
202*4882a593Smuzhiyun  * buses which make struct device available late such as I2C.
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  * @dev_name: Result of dev_name() for the consumer.
205*4882a593Smuzhiyun  * @supply: Name for the supply.
206*4882a593Smuzhiyun  */
207*4882a593Smuzhiyun struct regulator_consumer_supply {
208*4882a593Smuzhiyun 	const char *dev_name;   /* dev_name() for consumer */
209*4882a593Smuzhiyun 	const char *supply;	/* consumer supply - e.g. "vcc" */
210*4882a593Smuzhiyun };
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun /* Initialize struct regulator_consumer_supply */
213*4882a593Smuzhiyun #define REGULATOR_SUPPLY(_name, _dev_name)			\
214*4882a593Smuzhiyun {								\
215*4882a593Smuzhiyun 	.supply		= _name,				\
216*4882a593Smuzhiyun 	.dev_name	= _dev_name,				\
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun /**
220*4882a593Smuzhiyun  * struct regulator_init_data - regulator platform initialisation data.
221*4882a593Smuzhiyun  *
222*4882a593Smuzhiyun  * Initialisation constraints, our supply and consumers supplies.
223*4882a593Smuzhiyun  *
224*4882a593Smuzhiyun  * @supply_regulator: Parent regulator.  Specified using the regulator name
225*4882a593Smuzhiyun  *                    as it appears in the name field in sysfs, which can
226*4882a593Smuzhiyun  *                    be explicitly set using the constraints field 'name'.
227*4882a593Smuzhiyun  *
228*4882a593Smuzhiyun  * @constraints: Constraints.  These must be specified for the regulator to
229*4882a593Smuzhiyun  *               be usable.
230*4882a593Smuzhiyun  * @num_consumer_supplies: Number of consumer device supplies.
231*4882a593Smuzhiyun  * @consumer_supplies: Consumer device supply configuration.
232*4882a593Smuzhiyun  *
233*4882a593Smuzhiyun  * @regulator_init: Callback invoked when the regulator has been registered.
234*4882a593Smuzhiyun  * @driver_data: Data passed to regulator_init.
235*4882a593Smuzhiyun  */
236*4882a593Smuzhiyun struct regulator_init_data {
237*4882a593Smuzhiyun 	const char *supply_regulator;        /* or NULL for system supply */
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	struct regulation_constraints constraints;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 	int num_consumer_supplies;
242*4882a593Smuzhiyun 	struct regulator_consumer_supply *consumer_supplies;
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun 	/* optional regulator machine specific init */
245*4882a593Smuzhiyun 	int (*regulator_init)(void *driver_data);
246*4882a593Smuzhiyun 	void *driver_data;	/* core does not touch this */
247*4882a593Smuzhiyun };
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun #ifdef CONFIG_REGULATOR
250*4882a593Smuzhiyun void regulator_has_full_constraints(void);
251*4882a593Smuzhiyun #else
regulator_has_full_constraints(void)252*4882a593Smuzhiyun static inline void regulator_has_full_constraints(void)
253*4882a593Smuzhiyun {
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun #endif
256*4882a593Smuzhiyun 
regulator_suspend_prepare(suspend_state_t state)257*4882a593Smuzhiyun static inline int regulator_suspend_prepare(suspend_state_t state)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun 	return 0;
260*4882a593Smuzhiyun }
regulator_suspend_finish(void)261*4882a593Smuzhiyun static inline int regulator_suspend_finish(void)
262*4882a593Smuzhiyun {
263*4882a593Smuzhiyun 	return 0;
264*4882a593Smuzhiyun }
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun #endif
267