Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
4c1184e8 LG |
2 | /* |
3 | * machine.h -- SoC Regulator support, machine/board driver API. | |
4 | * | |
5 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | |
6 | * | |
1dd68f01 | 7 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
4c1184e8 | 8 | * |
4c1184e8 LG |
9 | * Regulator Machine/Board Interface. |
10 | */ | |
11 | ||
12 | #ifndef __LINUX_REGULATOR_MACHINE_H_ | |
13 | #define __LINUX_REGULATOR_MACHINE_H_ | |
14 | ||
15 | #include <linux/regulator/consumer.h> | |
16 | #include <linux/suspend.h> | |
17 | ||
18 | struct regulator; | |
19 | ||
20 | /* | |
21 | * Regulator operation constraint flags. These flags are used to enable | |
22 | * certain regulator operations and can be OR'ed together. | |
23 | * | |
24 | * VOLTAGE: Regulator output voltage can be changed by software on this | |
25 | * board/machine. | |
26 | * CURRENT: Regulator output current can be changed by software on this | |
27 | * board/machine. | |
28 | * MODE: Regulator operating mode can be changed by software on this | |
29 | * board/machine. | |
30 | * STATUS: Regulator can be enabled and disabled. | |
31 | * DRMS: Dynamic Regulator Mode Switching is enabled for this regulator. | |
f59c8f9f | 32 | * BYPASS: Regulator can be put into bypass mode |
4c1184e8 LG |
33 | */ |
34 | ||
35 | #define REGULATOR_CHANGE_VOLTAGE 0x1 | |
36 | #define REGULATOR_CHANGE_CURRENT 0x2 | |
37 | #define REGULATOR_CHANGE_MODE 0x4 | |
38 | #define REGULATOR_CHANGE_STATUS 0x8 | |
39 | #define REGULATOR_CHANGE_DRMS 0x10 | |
f59c8f9f | 40 | #define REGULATOR_CHANGE_BYPASS 0x20 |
4c1184e8 | 41 | |
72069f99 CZ |
42 | /* |
43 | * operations in suspend mode | |
44 | * DO_NOTHING_IN_SUSPEND - the default value | |
45 | * DISABLE_IN_SUSPEND - turn off regulator in suspend states | |
46 | * ENABLE_IN_SUSPEND - keep regulator on in suspend states | |
47 | */ | |
3edd79cf MS |
48 | #define DO_NOTHING_IN_SUSPEND 0 |
49 | #define DISABLE_IN_SUSPEND 1 | |
50 | #define ENABLE_IN_SUSPEND 2 | |
72069f99 | 51 | |
8156c7dd OR |
52 | /* |
53 | * Default time window (in milliseconds) following a critical under-voltage | |
54 | * event during which less critical actions can be safely carried out by the | |
55 | * system. | |
56 | */ | |
57 | #define REGULATOR_DEF_UV_LESS_CRITICAL_WINDOW_MS 10 | |
58 | ||
670666b9 LD |
59 | /* Regulator active discharge flags */ |
60 | enum regulator_active_discharge { | |
61 | REGULATOR_ACTIVE_DISCHARGE_DEFAULT, | |
62 | REGULATOR_ACTIVE_DISCHARGE_DISABLE, | |
63 | REGULATOR_ACTIVE_DISCHARGE_ENABLE, | |
64 | }; | |
65 | ||
4c1184e8 | 66 | /** |
2e7e65ce | 67 | * struct regulator_state - regulator state during low power system states |
4c1184e8 | 68 | * |
638f85c5 MB |
69 | * This describes a regulators state during a system wide low power |
70 | * state. One of enabled or disabled must be set for the | |
71 | * configuration to be applied. | |
c8e7e464 | 72 | * |
f7efad10 CZ |
73 | * @uV: Default operating voltage during suspend, it can be adjusted |
74 | * among <min_uV, max_uV>. | |
75 | * @min_uV: Minimum suspend voltage may be set. | |
76 | * @max_uV: Maximum suspend voltage may be set. | |
c8e7e464 | 77 | * @mode: Operating mode during suspend. |
72069f99 CZ |
78 | * @enabled: operations during suspend. |
79 | * - DO_NOTHING_IN_SUSPEND | |
80 | * - DISABLE_IN_SUSPEND | |
81 | * - ENABLE_IN_SUSPEND | |
f7efad10 | 82 | * @changeable: Is this state can be switched between enabled/disabled, |
4c1184e8 LG |
83 | */ |
84 | struct regulator_state { | |
f7efad10 CZ |
85 | int uV; |
86 | int min_uV; | |
87 | int max_uV; | |
88 | unsigned int mode; | |
72069f99 | 89 | int enabled; |
f7efad10 | 90 | bool changeable; |
4c1184e8 LG |
91 | }; |
92 | ||
89a6a5e5 MV |
93 | #define REGULATOR_NOTIF_LIMIT_DISABLE -1 |
94 | #define REGULATOR_NOTIF_LIMIT_ENABLE -2 | |
95 | struct notification_limit { | |
96 | int prot; | |
97 | int err; | |
98 | int warn; | |
99 | }; | |
100 | ||
4c1184e8 LG |
101 | /** |
102 | * struct regulation_constraints - regulator operating constraints. | |
103 | * | |
104 | * This struct describes regulator and board/machine specific constraints. | |
c8e7e464 MB |
105 | * |
106 | * @name: Descriptive name for the constraints, used for display purposes. | |
107 | * | |
108 | * @min_uV: Smallest voltage consumers may set. | |
109 | * @max_uV: Largest voltage consumers may set. | |
bf5892a8 MB |
110 | * @uV_offset: Offset applied to voltages from consumer to compensate for |
111 | * voltage drops. | |
c8e7e464 | 112 | * |
15c08f66 | 113 | * @min_uA: Smallest current consumers may set. |
c8e7e464 | 114 | * @max_uA: Largest current consumers may set. |
36e4f839 | 115 | * @ilim_uA: Maximum input current. |
42d7c87b | 116 | * @pw_budget_mW: Power budget for the regulator in mW. |
22a10bca | 117 | * @system_load: Load that isn't captured by any consumer requests. |
c8e7e464 | 118 | * |
89a6a5e5 MV |
119 | * @over_curr_limits: Limits for acting on over current. |
120 | * @over_voltage_limits: Limits for acting on over voltage. | |
121 | * @under_voltage_limits: Limits for acting on under voltage. | |
122 | * @temp_limits: Limits for acting on over temperature. | |
78bbb7c3 | 123 | * |
a085a31a | 124 | * @max_spread: Max possible spread between coupled regulators |
a98bcaa9 | 125 | * @max_uV_step: Max possible step change in voltage |
c8e7e464 MB |
126 | * @valid_modes_mask: Mask of modes which may be configured by consumers. |
127 | * @valid_ops_mask: Operations which may be performed by consumers. | |
128 | * | |
129 | * @always_on: Set if the regulator should never be disabled. | |
130 | * @boot_on: Set if the regulator is enabled when the system is initially | |
cacf90f2 MB |
131 | * started. If the regulator is not enabled by the hardware or |
132 | * bootloader then it will be enabled when the constraints are | |
133 | * applied. | |
c8e7e464 | 134 | * @apply_uV: Apply the voltage constraint when initialising. |
a8dbfeed | 135 | * @ramp_disable: Disable ramp delay when initialising or when setting voltage. |
c751ad0d | 136 | * @soft_start: Enable soft start so that voltage ramps slowly. |
23c779b9 | 137 | * @pull_down: Enable pull down when regulator is disabled. |
8156c7dd OR |
138 | * @system_critical: Set if the regulator is critical to system stability or |
139 | * functionality. | |
abf2f825 | 140 | * @over_current_protection: Auto disable on over current event. |
c8e7e464 | 141 | * |
89a6a5e5 MV |
142 | * @over_current_detection: Configure over current limits. |
143 | * @over_voltage_detection: Configure over voltage limits. | |
144 | * @under_voltage_detection: Configure under voltage limits. | |
145 | * @over_temp_detection: Configure over temperature limits. | |
146 | * | |
c8e7e464 MB |
147 | * @input_uV: Input voltage for regulator when supplied by another regulator. |
148 | * | |
149 | * @state_disk: State for regulator when system is suspended in disk mode. | |
150 | * @state_mem: State for regulator when system is suspended in mem mode. | |
151 | * @state_standby: State for regulator when system is suspended in standby | |
152 | * mode. | |
153 | * @initial_state: Suspend state to set by default. | |
a308466c | 154 | * @initial_mode: Mode to set at startup. |
ea38d13f | 155 | * @ramp_delay: Time to settle down after voltage change (unit: uV/us) |
d6c1dc3f LD |
156 | * @settling_time: Time to settle down after voltage change when voltage |
157 | * change is non-linear (unit: microseconds). | |
3ffad468 MK |
158 | * @settling_time_up: Time to settle down after voltage increase when voltage |
159 | * change is non-linear (unit: microseconds). | |
160 | * @settling_time_down : Time to settle down after voltage decrease when | |
161 | * voltage change is non-linear (unit: microseconds). | |
670666b9 LD |
162 | * @active_discharge: Enable/disable active discharge. The enum |
163 | * regulator_active_discharge values are used for | |
164 | * initialisation. | |
00c877c6 | 165 | * @enable_time: Turn-on time of the rails (unit: microseconds) |
1e22152a OR |
166 | * @uv_less_critical_window_ms: Specifies the time window (in milliseconds) |
167 | * following a critical under-voltage (UV) event | |
168 | * during which less critical actions can be | |
169 | * safely carried out by the system (for example | |
170 | * logging). After this time window more critical | |
171 | * actions should be done (for example prevent | |
172 | * HW damage). | |
4c1184e8 LG |
173 | */ |
174 | struct regulation_constraints { | |
175 | ||
0151546f | 176 | const char *name; |
4c1184e8 LG |
177 | |
178 | /* voltage output range (inclusive) - for voltage control */ | |
179 | int min_uV; | |
180 | int max_uV; | |
181 | ||
bf5892a8 MB |
182 | int uV_offset; |
183 | ||
4c1184e8 LG |
184 | /* current output range (inclusive) - for current control */ |
185 | int min_uA; | |
186 | int max_uA; | |
36e4f839 | 187 | int ilim_uA; |
4c1184e8 | 188 | |
42d7c87b | 189 | int pw_budget_mW; |
22a10bca SB |
190 | int system_load; |
191 | ||
a085a31a | 192 | /* used for coupled regulators */ |
d8ca7d18 | 193 | u32 *max_spread; |
a085a31a | 194 | |
85254bcf DO |
195 | /* used for changing voltage in steps */ |
196 | int max_uV_step; | |
197 | ||
4c1184e8 LG |
198 | /* valid regulator operating modes for this machine */ |
199 | unsigned int valid_modes_mask; | |
200 | ||
201 | /* valid operations for regulator on this machine */ | |
202 | unsigned int valid_ops_mask; | |
203 | ||
204 | /* regulator input voltage - only if supply is another regulator */ | |
205 | int input_uV; | |
206 | ||
207 | /* regulator suspend states for global PMIC STANDBY/HIBERNATE */ | |
208 | struct regulator_state state_disk; | |
209 | struct regulator_state state_mem; | |
210 | struct regulator_state state_standby; | |
89a6a5e5 MV |
211 | struct notification_limit over_curr_limits; |
212 | struct notification_limit over_voltage_limits; | |
213 | struct notification_limit under_voltage_limits; | |
214 | struct notification_limit temp_limits; | |
4c1184e8 LG |
215 | suspend_state_t initial_state; /* suspend state to set at init */ |
216 | ||
a308466c MB |
217 | /* mode to set on startup */ |
218 | unsigned int initial_mode; | |
219 | ||
6f0b2c69 | 220 | unsigned int ramp_delay; |
d6c1dc3f | 221 | unsigned int settling_time; |
3ffad468 MK |
222 | unsigned int settling_time_up; |
223 | unsigned int settling_time_down; | |
00c877c6 | 224 | unsigned int enable_time; |
1e22152a | 225 | unsigned int uv_less_critical_window_ms; |
6f0b2c69 | 226 | |
670666b9 LD |
227 | unsigned int active_discharge; |
228 | ||
2e7e65ce | 229 | /* constraint flags */ |
4c1184e8 LG |
230 | unsigned always_on:1; /* regulator never off when system is on */ |
231 | unsigned boot_on:1; /* bootloader/firmware enabled regulator */ | |
2e7e65ce | 232 | unsigned apply_uV:1; /* apply uV constraint if min == max */ |
1653ccf4 | 233 | unsigned ramp_disable:1; /* disable ramp delay */ |
57f66b78 | 234 | unsigned soft_start:1; /* ramp voltage slowly */ |
23c779b9 | 235 | unsigned pull_down:1; /* pull down resistor when regulator off */ |
8156c7dd | 236 | unsigned system_critical:1; /* critical to system stability */ |
3a003bae | 237 | unsigned over_current_protection:1; /* auto disable on over current */ |
89a6a5e5 MV |
238 | unsigned over_current_detection:1; /* notify on over current */ |
239 | unsigned over_voltage_detection:1; /* notify on over voltage */ | |
240 | unsigned under_voltage_detection:1; /* notify on under voltage */ | |
241 | unsigned over_temp_detection:1; /* notify on over temperature */ | |
4c1184e8 LG |
242 | }; |
243 | ||
a5766f11 LG |
244 | /** |
245 | * struct regulator_consumer_supply - supply -> device mapping | |
246 | * | |
15c08f66 AL |
247 | * This maps a supply name to a device. Use of dev_name allows support for |
248 | * buses which make struct device available late such as I2C. | |
c8e7e464 | 249 | * |
40f9244f | 250 | * @dev_name: Result of dev_name() for the consumer. |
c8e7e464 | 251 | * @supply: Name for the supply. |
a5766f11 LG |
252 | */ |
253 | struct regulator_consumer_supply { | |
40f9244f | 254 | const char *dev_name; /* dev_name() for consumer */ |
a5766f11 LG |
255 | const char *supply; /* consumer supply - e.g. "vcc" */ |
256 | }; | |
4c1184e8 | 257 | |
ed654324 | 258 | /* Initialize struct regulator_consumer_supply */ |
259 | #define REGULATOR_SUPPLY(_name, _dev_name) \ | |
260 | { \ | |
261 | .supply = _name, \ | |
262 | .dev_name = _dev_name, \ | |
263 | } | |
264 | ||
a5766f11 LG |
265 | /** |
266 | * struct regulator_init_data - regulator platform initialisation data. | |
267 | * | |
268 | * Initialisation constraints, our supply and consumers supplies. | |
c8e7e464 | 269 | * |
0178f3e2 MB |
270 | * @supply_regulator: Parent regulator. Specified using the regulator name |
271 | * as it appears in the name field in sysfs, which can | |
272 | * be explicitly set using the constraints field 'name'. | |
c8e7e464 MB |
273 | * |
274 | * @constraints: Constraints. These must be specified for the regulator to | |
275 | * be usable. | |
276 | * @num_consumer_supplies: Number of consumer device supplies. | |
277 | * @consumer_supplies: Consumer device supply configuration. | |
c8e7e464 | 278 | * @driver_data: Data passed to regulator_init. |
a5766f11 LG |
279 | */ |
280 | struct regulator_init_data { | |
0178f3e2 | 281 | const char *supply_regulator; /* or NULL for system supply */ |
4c1184e8 | 282 | |
a5766f11 | 283 | struct regulation_constraints constraints; |
4c1184e8 | 284 | |
a5766f11 LG |
285 | int num_consumer_supplies; |
286 | struct regulator_consumer_supply *consumer_supplies; | |
287 | ||
602ff58a | 288 | /* optional regulator machine specific data */ |
a5766f11 LG |
289 | void *driver_data; /* core does not touch this */ |
290 | }; | |
4c1184e8 | 291 | |
9c19bc04 | 292 | #ifdef CONFIG_REGULATOR |
ca725561 | 293 | void regulator_has_full_constraints(void); |
9c19bc04 MB |
294 | #else |
295 | static inline void regulator_has_full_constraints(void) | |
296 | { | |
297 | } | |
aa27bbc6 CZ |
298 | #endif |
299 | ||
50910276 KK |
300 | static inline int regulator_suspend_prepare(suspend_state_t state) |
301 | { | |
302 | return 0; | |
303 | } | |
304 | static inline int regulator_suspend_finish(void) | |
305 | { | |
306 | return 0; | |
307 | } | |
ca725561 | 308 | |
4c1184e8 | 309 | #endif |