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