]>
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 | |
670666b9 LD |
52 | /* Regulator active discharge flags */ |
53 | enum regulator_active_discharge { | |
54 | REGULATOR_ACTIVE_DISCHARGE_DEFAULT, | |
55 | REGULATOR_ACTIVE_DISCHARGE_DISABLE, | |
56 | REGULATOR_ACTIVE_DISCHARGE_ENABLE, | |
57 | }; | |
58 | ||
4c1184e8 | 59 | /** |
2e7e65ce | 60 | * struct regulator_state - regulator state during low power system states |
4c1184e8 | 61 | * |
638f85c5 MB |
62 | * This describes a regulators state during a system wide low power |
63 | * state. One of enabled or disabled must be set for the | |
64 | * configuration to be applied. | |
c8e7e464 | 65 | * |
f7efad10 CZ |
66 | * @uV: Default operating voltage during suspend, it can be adjusted |
67 | * among <min_uV, max_uV>. | |
68 | * @min_uV: Minimum suspend voltage may be set. | |
69 | * @max_uV: Maximum suspend voltage may be set. | |
c8e7e464 | 70 | * @mode: Operating mode during suspend. |
72069f99 CZ |
71 | * @enabled: operations during suspend. |
72 | * - DO_NOTHING_IN_SUSPEND | |
73 | * - DISABLE_IN_SUSPEND | |
74 | * - ENABLE_IN_SUSPEND | |
f7efad10 | 75 | * @changeable: Is this state can be switched between enabled/disabled, |
4c1184e8 LG |
76 | */ |
77 | struct regulator_state { | |
f7efad10 CZ |
78 | int uV; |
79 | int min_uV; | |
80 | int max_uV; | |
81 | unsigned int mode; | |
72069f99 | 82 | int enabled; |
f7efad10 | 83 | bool changeable; |
4c1184e8 LG |
84 | }; |
85 | ||
86 | /** | |
87 | * struct regulation_constraints - regulator operating constraints. | |
88 | * | |
89 | * This struct describes regulator and board/machine specific constraints. | |
c8e7e464 MB |
90 | * |
91 | * @name: Descriptive name for the constraints, used for display purposes. | |
92 | * | |
93 | * @min_uV: Smallest voltage consumers may set. | |
94 | * @max_uV: Largest voltage consumers may set. | |
bf5892a8 MB |
95 | * @uV_offset: Offset applied to voltages from consumer to compensate for |
96 | * voltage drops. | |
c8e7e464 | 97 | * |
15c08f66 | 98 | * @min_uA: Smallest current consumers may set. |
c8e7e464 | 99 | * @max_uA: Largest current consumers may set. |
36e4f839 | 100 | * @ilim_uA: Maximum input current. |
22a10bca | 101 | * @system_load: Load that isn't captured by any consumer requests. |
c8e7e464 | 102 | * |
a085a31a | 103 | * @max_spread: Max possible spread between coupled regulators |
c8e7e464 MB |
104 | * @valid_modes_mask: Mask of modes which may be configured by consumers. |
105 | * @valid_ops_mask: Operations which may be performed by consumers. | |
106 | * | |
107 | * @always_on: Set if the regulator should never be disabled. | |
108 | * @boot_on: Set if the regulator is enabled when the system is initially | |
cacf90f2 MB |
109 | * started. If the regulator is not enabled by the hardware or |
110 | * bootloader then it will be enabled when the constraints are | |
111 | * applied. | |
c8e7e464 | 112 | * @apply_uV: Apply the voltage constraint when initialising. |
a8dbfeed | 113 | * @ramp_disable: Disable ramp delay when initialising or when setting voltage. |
c751ad0d | 114 | * @soft_start: Enable soft start so that voltage ramps slowly. |
23c779b9 | 115 | * @pull_down: Enable pull down when regulator is disabled. |
abf2f825 | 116 | * @over_current_protection: Auto disable on over current event. |
c8e7e464 MB |
117 | * |
118 | * @input_uV: Input voltage for regulator when supplied by another regulator. | |
119 | * | |
120 | * @state_disk: State for regulator when system is suspended in disk mode. | |
121 | * @state_mem: State for regulator when system is suspended in mem mode. | |
122 | * @state_standby: State for regulator when system is suspended in standby | |
123 | * mode. | |
124 | * @initial_state: Suspend state to set by default. | |
a308466c | 125 | * @initial_mode: Mode to set at startup. |
ea38d13f | 126 | * @ramp_delay: Time to settle down after voltage change (unit: uV/us) |
d6c1dc3f LD |
127 | * @settling_time: Time to settle down after voltage change when voltage |
128 | * change is non-linear (unit: microseconds). | |
3ffad468 MK |
129 | * @settling_time_up: Time to settle down after voltage increase when voltage |
130 | * change is non-linear (unit: microseconds). | |
131 | * @settling_time_down : Time to settle down after voltage decrease when | |
132 | * voltage change is non-linear (unit: microseconds). | |
670666b9 LD |
133 | * @active_discharge: Enable/disable active discharge. The enum |
134 | * regulator_active_discharge values are used for | |
135 | * initialisation. | |
00c877c6 | 136 | * @enable_time: Turn-on time of the rails (unit: microseconds) |
4c1184e8 LG |
137 | */ |
138 | struct regulation_constraints { | |
139 | ||
0151546f | 140 | const char *name; |
4c1184e8 LG |
141 | |
142 | /* voltage output range (inclusive) - for voltage control */ | |
143 | int min_uV; | |
144 | int max_uV; | |
145 | ||
bf5892a8 MB |
146 | int uV_offset; |
147 | ||
4c1184e8 LG |
148 | /* current output range (inclusive) - for current control */ |
149 | int min_uA; | |
150 | int max_uA; | |
36e4f839 | 151 | int ilim_uA; |
4c1184e8 | 152 | |
22a10bca SB |
153 | int system_load; |
154 | ||
a085a31a MP |
155 | /* used for coupled regulators */ |
156 | int max_spread; | |
157 | ||
85254bcf DO |
158 | /* used for changing voltage in steps */ |
159 | int max_uV_step; | |
160 | ||
4c1184e8 LG |
161 | /* valid regulator operating modes for this machine */ |
162 | unsigned int valid_modes_mask; | |
163 | ||
164 | /* valid operations for regulator on this machine */ | |
165 | unsigned int valid_ops_mask; | |
166 | ||
167 | /* regulator input voltage - only if supply is another regulator */ | |
168 | int input_uV; | |
169 | ||
170 | /* regulator suspend states for global PMIC STANDBY/HIBERNATE */ | |
171 | struct regulator_state state_disk; | |
172 | struct regulator_state state_mem; | |
173 | struct regulator_state state_standby; | |
174 | suspend_state_t initial_state; /* suspend state to set at init */ | |
175 | ||
a308466c MB |
176 | /* mode to set on startup */ |
177 | unsigned int initial_mode; | |
178 | ||
6f0b2c69 | 179 | unsigned int ramp_delay; |
d6c1dc3f | 180 | unsigned int settling_time; |
3ffad468 MK |
181 | unsigned int settling_time_up; |
182 | unsigned int settling_time_down; | |
00c877c6 | 183 | unsigned int enable_time; |
6f0b2c69 | 184 | |
670666b9 LD |
185 | unsigned int active_discharge; |
186 | ||
2e7e65ce | 187 | /* constraint flags */ |
4c1184e8 LG |
188 | unsigned always_on:1; /* regulator never off when system is on */ |
189 | unsigned boot_on:1; /* bootloader/firmware enabled regulator */ | |
2e7e65ce | 190 | unsigned apply_uV:1; /* apply uV constraint if min == max */ |
1653ccf4 | 191 | unsigned ramp_disable:1; /* disable ramp delay */ |
57f66b78 | 192 | unsigned soft_start:1; /* ramp voltage slowly */ |
23c779b9 | 193 | unsigned pull_down:1; /* pull down resistor when regulator off */ |
3a003bae | 194 | unsigned over_current_protection:1; /* auto disable on over current */ |
4c1184e8 LG |
195 | }; |
196 | ||
a5766f11 LG |
197 | /** |
198 | * struct regulator_consumer_supply - supply -> device mapping | |
199 | * | |
15c08f66 AL |
200 | * This maps a supply name to a device. Use of dev_name allows support for |
201 | * buses which make struct device available late such as I2C. | |
c8e7e464 | 202 | * |
40f9244f | 203 | * @dev_name: Result of dev_name() for the consumer. |
c8e7e464 | 204 | * @supply: Name for the supply. |
a5766f11 LG |
205 | */ |
206 | struct regulator_consumer_supply { | |
40f9244f | 207 | const char *dev_name; /* dev_name() for consumer */ |
a5766f11 LG |
208 | const char *supply; /* consumer supply - e.g. "vcc" */ |
209 | }; | |
4c1184e8 | 210 | |
ed654324 | 211 | /* Initialize struct regulator_consumer_supply */ |
212 | #define REGULATOR_SUPPLY(_name, _dev_name) \ | |
213 | { \ | |
214 | .supply = _name, \ | |
215 | .dev_name = _dev_name, \ | |
216 | } | |
217 | ||
a5766f11 LG |
218 | /** |
219 | * struct regulator_init_data - regulator platform initialisation data. | |
220 | * | |
221 | * Initialisation constraints, our supply and consumers supplies. | |
c8e7e464 | 222 | * |
0178f3e2 MB |
223 | * @supply_regulator: Parent regulator. Specified using the regulator name |
224 | * as it appears in the name field in sysfs, which can | |
225 | * be explicitly set using the constraints field 'name'. | |
c8e7e464 MB |
226 | * |
227 | * @constraints: Constraints. These must be specified for the regulator to | |
228 | * be usable. | |
229 | * @num_consumer_supplies: Number of consumer device supplies. | |
230 | * @consumer_supplies: Consumer device supply configuration. | |
231 | * | |
232 | * @regulator_init: Callback invoked when the regulator has been registered. | |
233 | * @driver_data: Data passed to regulator_init. | |
a5766f11 LG |
234 | */ |
235 | struct regulator_init_data { | |
0178f3e2 | 236 | const char *supply_regulator; /* or NULL for system supply */ |
4c1184e8 | 237 | |
a5766f11 | 238 | struct regulation_constraints constraints; |
4c1184e8 | 239 | |
a5766f11 LG |
240 | int num_consumer_supplies; |
241 | struct regulator_consumer_supply *consumer_supplies; | |
242 | ||
243 | /* optional regulator machine specific init */ | |
244 | int (*regulator_init)(void *driver_data); | |
245 | void *driver_data; /* core does not touch this */ | |
246 | }; | |
4c1184e8 | 247 | |
9c19bc04 | 248 | #ifdef CONFIG_REGULATOR |
ca725561 | 249 | void regulator_has_full_constraints(void); |
9c19bc04 MB |
250 | #else |
251 | static inline void regulator_has_full_constraints(void) | |
252 | { | |
253 | } | |
aa27bbc6 CZ |
254 | #endif |
255 | ||
50910276 KK |
256 | static inline int regulator_suspend_prepare(suspend_state_t state) |
257 | { | |
258 | return 0; | |
259 | } | |
260 | static inline int regulator_suspend_finish(void) | |
261 | { | |
262 | return 0; | |
263 | } | |
ca725561 | 264 | |
4c1184e8 | 265 | #endif |