Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
571a354b LG |
2 | /* |
3 | * driver.h -- SoC Regulator driver support. | |
4 | * | |
5 | * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. | |
6 | * | |
1dd68f01 | 7 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
571a354b | 8 | * |
571a354b LG |
9 | * Regulator Driver Interface. |
10 | */ | |
11 | ||
12 | #ifndef __LINUX_REGULATOR_DRIVER_H_ | |
13 | #define __LINUX_REGULATOR_DRIVER_H_ | |
14 | ||
15 | #include <linux/device.h> | |
60ab7f41 | 16 | #include <linux/linear_range.h> |
ced55d4e | 17 | #include <linux/notifier.h> |
571a354b | 18 | #include <linux/regulator/consumer.h> |
f8702f9e | 19 | #include <linux/ww_mutex.h> |
571a354b | 20 | |
e45e290a | 21 | struct gpio_desc; |
65b19ce6 | 22 | struct regmap; |
571a354b | 23 | struct regulator_dev; |
bfa21a0d | 24 | struct regulator_config; |
a5766f11 | 25 | struct regulator_init_data; |
f19b00da | 26 | struct regulator_enable_gpio; |
571a354b | 27 | |
853116a1 DB |
28 | enum regulator_status { |
29 | REGULATOR_STATUS_OFF, | |
30 | REGULATOR_STATUS_ON, | |
31 | REGULATOR_STATUS_ERROR, | |
32 | /* fast/normal/idle/standby are flavors of "on" */ | |
33 | REGULATOR_STATUS_FAST, | |
34 | REGULATOR_STATUS_NORMAL, | |
35 | REGULATOR_STATUS_IDLE, | |
36 | REGULATOR_STATUS_STANDBY, | |
f59c8f9f MB |
37 | /* The regulator is enabled but not regulating */ |
38 | REGULATOR_STATUS_BYPASS, | |
1beaf762 KG |
39 | /* in case that any other status doesn't apply */ |
40 | REGULATOR_STATUS_UNDEFINED, | |
853116a1 DB |
41 | }; |
42 | ||
89a6a5e5 MV |
43 | enum regulator_detection_severity { |
44 | /* Hardware shut down voltage outputs if condition is detected */ | |
45 | REGULATOR_SEVERITY_PROT, | |
46 | /* Hardware is probably damaged/inoperable */ | |
47 | REGULATOR_SEVERITY_ERR, | |
48 | /* Hardware is still recoverable but recovery action must be taken */ | |
49 | REGULATOR_SEVERITY_WARN, | |
50 | }; | |
51 | ||
60ab7f41 | 52 | /* Initialize struct linear_range for regulators */ |
8828bae4 | 53 | #define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \ |
67ba055d | 54 | LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) |
8828bae4 | 55 | |
571a354b LG |
56 | /** |
57 | * struct regulator_ops - regulator operations. | |
58 | * | |
3b2a6061 DB |
59 | * @enable: Configure the regulator as enabled. |
60 | * @disable: Configure the regulator as disabled. | |
d87b969d WS |
61 | * @is_enabled: Return 1 if the regulator is enabled, 0 if not. |
62 | * May also return negative errno. | |
c8e7e464 MB |
63 | * |
64 | * @set_voltage: Set the voltage for the regulator within the range specified. | |
65 | * The driver should select the voltage closest to min_uV. | |
e8eef82b MB |
66 | * @set_voltage_sel: Set the voltage for the regulator using the specified |
67 | * selector. | |
e843fc46 | 68 | * @map_voltage: Convert a voltage into a selector |
84b3a7c9 DA |
69 | * @get_voltage: Return the currently configured voltage for the regulator; |
70 | * return -ENOTRECOVERABLE if regulator can't be read at | |
71 | * bootup and hasn't been set yet. | |
476c2d83 | 72 | * @get_voltage_sel: Return the currently configured voltage selector for the |
84b3a7c9 DA |
73 | * regulator; return -ENOTRECOVERABLE if regulator can't |
74 | * be read at bootup and hasn't been set yet. | |
4367cfdc DB |
75 | * @list_voltage: Return one of the supported voltages, in microvolts; zero |
76 | * if the selector indicates a voltage that is unusable on this system; | |
77 | * or negative errno. Selectors range from zero to one less than | |
78 | * regulator_desc.n_voltages. Voltages may be reported in any order. | |
c8e7e464 | 79 | * |
c8e7e464 | 80 | * @set_current_limit: Configure a limit for a current-limited regulator. |
89009e18 | 81 | * The driver should select the current closest to max_uA. |
3b2a6061 | 82 | * @get_current_limit: Get the configured limit for a current-limited regulator. |
36e4f839 | 83 | * @set_input_current_limit: Configure an input limit. |
c8e7e464 | 84 | * |
89a6a5e5 MV |
85 | * @set_over_current_protection: Support enabling of and setting limits for over |
86 | * current situation detection. Detection can be configured for three | |
87 | * levels of severity. | |
8d9f738f YS |
88 | * |
89 | * - REGULATOR_SEVERITY_PROT should automatically shut down the regulator(s). | |
90 | * | |
91 | * - REGULATOR_SEVERITY_ERR should indicate that over-current situation is | |
92 | * caused by an unrecoverable error but HW does not perform | |
93 | * automatic shut down. | |
94 | * | |
95 | * - REGULATOR_SEVERITY_WARN should indicate situation where hardware is | |
96 | * still believed to not be damaged but that a board sepcific | |
97 | * recovery action is needed. If lim_uA is 0 the limit should not | |
98 | * be changed but the detection should just be enabled/disabled as | |
99 | * is requested. | |
100 | * | |
89a6a5e5 MV |
101 | * @set_over_voltage_protection: Support enabling of and setting limits for over |
102 | * voltage situation detection. Detection can be configured for same | |
92b13482 | 103 | * severities as over current protection. Units of uV. |
89a6a5e5 | 104 | * @set_under_voltage_protection: Support enabling of and setting limits for |
92b13482 MV |
105 | * under voltage situation detection. Detection can be configured for same |
106 | * severities as over current protection. Units of uV. | |
89a6a5e5 | 107 | * @set_thermal_protection: Support enabling of and setting limits for over |
92b13482 MV |
108 | * temperature situation detection.Detection can be configured for same |
109 | * severities as over current protection. Units of degree Kelvin. | |
abf2f825 | 110 | * |
670666b9 LD |
111 | * @set_active_discharge: Set active discharge enable/disable of regulators. |
112 | * | |
9f653251 | 113 | * @set_mode: Set the configured operating mode for the regulator. |
3b2a6061 | 114 | * @get_mode: Get the configured operating mode for the regulator. |
1b5b4221 | 115 | * @get_error_flags: Get the current error(s) for the regulator. |
3b2a6061 DB |
116 | * @get_status: Return actual (not as-configured) status of regulator, as a |
117 | * REGULATOR_STATUS value (or negative errno) | |
c8e7e464 MB |
118 | * @get_optimum_mode: Get the most efficient operating mode for the regulator |
119 | * when running with the specified parameters. | |
8f4490e0 | 120 | * @set_load: Set the load for the regulator. |
c8e7e464 | 121 | * |
f59c8f9f MB |
122 | * @set_bypass: Set the regulator in bypass mode. |
123 | * @get_bypass: Get the regulator bypass mode state. | |
124 | * | |
31aae2be | 125 | * @enable_time: Time taken for the regulator voltage output voltage to |
77af1b26 | 126 | * stabilise after being enabled, in microseconds. |
6f0b2c69 YSB |
127 | * @set_ramp_delay: Set the ramp delay for the regulator. The driver should |
128 | * select ramp delay equal to or less than(closest) ramp_delay. | |
73e705bf MK |
129 | * @set_voltage_time: Time taken for the regulator voltage output voltage |
130 | * to stabilise after being set to a new value, in microseconds. | |
131 | * The function receives the from and to voltage as input, it | |
132 | * should return the worst case. | |
77af1b26 LW |
133 | * @set_voltage_time_sel: Time taken for the regulator voltage output voltage |
134 | * to stabilise after being set to a new value, in microseconds. | |
73e705bf MK |
135 | * The function receives the from and to voltage selector as |
136 | * input, it should return the worst case. | |
c751ad0d | 137 | * @set_soft_start: Enable soft start for the regulator. |
31aae2be | 138 | * |
c8e7e464 MB |
139 | * @set_suspend_voltage: Set the voltage for the regulator when the system |
140 | * is suspended. | |
141 | * @set_suspend_enable: Mark the regulator as enabled when the system is | |
142 | * suspended. | |
143 | * @set_suspend_disable: Mark the regulator as disabled when the system is | |
144 | * suspended. | |
145 | * @set_suspend_mode: Set the operating mode for the regulator when the | |
146 | * system is suspended. | |
a98bcaa9 | 147 | * @resume: Resume operation of suspended regulator. |
23c779b9 SB |
148 | * @set_pull_down: Configure the regulator to pull down when the regulator |
149 | * is disabled. | |
150 | * | |
3b2a6061 DB |
151 | * This struct describes regulator operations which can be implemented by |
152 | * regulator chip drivers. | |
571a354b LG |
153 | */ |
154 | struct regulator_ops { | |
155 | ||
4367cfdc DB |
156 | /* enumerate supported voltages */ |
157 | int (*list_voltage) (struct regulator_dev *, unsigned selector); | |
158 | ||
571a354b | 159 | /* get/set regulator voltage */ |
3a93f2a9 MB |
160 | int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV, |
161 | unsigned *selector); | |
e843fc46 | 162 | int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV); |
e8eef82b | 163 | int (*set_voltage_sel) (struct regulator_dev *, unsigned selector); |
571a354b | 164 | int (*get_voltage) (struct regulator_dev *); |
476c2d83 | 165 | int (*get_voltage_sel) (struct regulator_dev *); |
571a354b LG |
166 | |
167 | /* get/set regulator current */ | |
168 | int (*set_current_limit) (struct regulator_dev *, | |
169 | int min_uA, int max_uA); | |
170 | int (*get_current_limit) (struct regulator_dev *); | |
171 | ||
36e4f839 | 172 | int (*set_input_current_limit) (struct regulator_dev *, int lim_uA); |
89a6a5e5 MV |
173 | int (*set_over_current_protection)(struct regulator_dev *, int lim_uA, |
174 | int severity, bool enable); | |
175 | int (*set_over_voltage_protection)(struct regulator_dev *, int lim_uV, | |
176 | int severity, bool enable); | |
177 | int (*set_under_voltage_protection)(struct regulator_dev *, int lim_uV, | |
178 | int severity, bool enable); | |
179 | int (*set_thermal_protection)(struct regulator_dev *, int lim, | |
180 | int severity, bool enable); | |
181 | int (*set_active_discharge)(struct regulator_dev *, bool enable); | |
36e4f839 | 182 | |
571a354b LG |
183 | /* enable/disable regulator */ |
184 | int (*enable) (struct regulator_dev *); | |
185 | int (*disable) (struct regulator_dev *); | |
186 | int (*is_enabled) (struct regulator_dev *); | |
187 | ||
fde297bb | 188 | /* get/set regulator operating mode (defined in consumer.h) */ |
571a354b LG |
189 | int (*set_mode) (struct regulator_dev *, unsigned int mode); |
190 | unsigned int (*get_mode) (struct regulator_dev *); | |
191 | ||
1b5b4221 AH |
192 | /* retrieve current error flags on the regulator */ |
193 | int (*get_error_flags)(struct regulator_dev *, unsigned int *flags); | |
194 | ||
77af1b26 | 195 | /* Time taken to enable or set voltage on the regulator */ |
31aae2be | 196 | int (*enable_time) (struct regulator_dev *); |
6f0b2c69 | 197 | int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay); |
73e705bf MK |
198 | int (*set_voltage_time) (struct regulator_dev *, int old_uV, |
199 | int new_uV); | |
77af1b26 LW |
200 | int (*set_voltage_time_sel) (struct regulator_dev *, |
201 | unsigned int old_selector, | |
202 | unsigned int new_selector); | |
31aae2be | 203 | |
57f66b78 SB |
204 | int (*set_soft_start) (struct regulator_dev *); |
205 | ||
853116a1 DB |
206 | /* report regulator status ... most other accessors report |
207 | * control inputs, this reports results of combining inputs | |
208 | * from Linux (and other sources) with the actual load. | |
3b2a6061 | 209 | * returns REGULATOR_STATUS_* or negative errno. |
853116a1 DB |
210 | */ |
211 | int (*get_status)(struct regulator_dev *); | |
212 | ||
571a354b LG |
213 | /* get most efficient regulator operating mode for load */ |
214 | unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, | |
215 | int output_uV, int load_uA); | |
8f4490e0 BA |
216 | /* set the load on the regulator */ |
217 | int (*set_load)(struct regulator_dev *, int load_uA); | |
571a354b | 218 | |
f59c8f9f MB |
219 | /* control and report on bypass mode */ |
220 | int (*set_bypass)(struct regulator_dev *dev, bool enable); | |
221 | int (*get_bypass)(struct regulator_dev *dev, bool *enable); | |
222 | ||
571a354b | 223 | /* the operations below are for configuration of regulator state when |
3de89609 | 224 | * its parent PMIC enters a global STANDBY/HIBERNATE state */ |
571a354b LG |
225 | |
226 | /* set regulator suspend voltage */ | |
227 | int (*set_suspend_voltage) (struct regulator_dev *, int uV); | |
228 | ||
229 | /* enable/disable regulator in suspend state */ | |
230 | int (*set_suspend_enable) (struct regulator_dev *); | |
231 | int (*set_suspend_disable) (struct regulator_dev *); | |
232 | ||
fde297bb | 233 | /* set regulator suspend operating mode (defined in consumer.h) */ |
571a354b | 234 | int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); |
23c779b9 | 235 | |
0380cf7d | 236 | int (*resume)(struct regulator_dev *rdev); |
f7efad10 | 237 | |
23c779b9 | 238 | int (*set_pull_down) (struct regulator_dev *); |
571a354b LG |
239 | }; |
240 | ||
241 | /* | |
242 | * Regulators can either control voltage or current. | |
243 | */ | |
244 | enum regulator_type { | |
245 | REGULATOR_VOLTAGE, | |
246 | REGULATOR_CURRENT, | |
247 | }; | |
248 | ||
249 | /** | |
c172708d | 250 | * struct regulator_desc - Static regulator descriptor |
571a354b | 251 | * |
c172708d MB |
252 | * Each regulator registered with the core is described with a |
253 | * structure of this type and a struct regulator_config. This | |
254 | * structure contains the non-varying parts of the regulator | |
255 | * description. | |
c8e7e464 MB |
256 | * |
257 | * @name: Identifying name for the regulator. | |
69511a45 | 258 | * @supply_name: Identifying the regulator supply |
a0c7b164 | 259 | * @of_match: Name used to identify regulator in DT. |
e7095c35 CM |
260 | * @of_match_full_name: A flag to indicate that the of_match string, if |
261 | * present, should be matched against the node full_name. | |
a0c7b164 | 262 | * @regulators_node: Name of node containing regulator definitions in DT. |
bfa21a0d KK |
263 | * @of_parse_cb: Optional callback called only if of_match is present. |
264 | * Will be called for each regulator parsed from DT, during | |
265 | * init_data parsing. | |
266 | * The regulator_config passed as argument to the callback will | |
267 | * be a copy of config passed to regulator_register, valid only | |
268 | * for this particular call. Callback may freely change the | |
269 | * config but it cannot store it for later usage. | |
270 | * Callback should return 0 on success or negative ERRNO | |
271 | * indicating failure. | |
e55f45b0 JB |
272 | * @init_cb: Optional callback called after the parsing of init_data. |
273 | * Allows the regulator to perform runtime init if necessary, | |
274 | * such as synching the regulator and the parsed constraints. | |
275 | * Callback should return 0 on success or negative ERRNO | |
276 | * indicating failure. | |
c8e7e464 MB |
277 | * @id: Numerical identifier for the regulator. |
278 | * @ops: Regulator operations table. | |
0ba4887c | 279 | * @irq: Interrupt number for the regulator. |
c8e7e464 MB |
280 | * @type: Indicates if the regulator is a voltage or current regulator. |
281 | * @owner: Module providing the regulator, used for refcounting. | |
bca7bbff | 282 | * |
bd7a2b60 PM |
283 | * @continuous_voltage_range: Indicates if the regulator can set any |
284 | * voltage within constrains range. | |
bca7bbff | 285 | * @n_voltages: Number of selectors available for ops.list_voltage(). |
a32e0c77 | 286 | * @n_current_limits: Number of selectors available for current limits |
bca7bbff MB |
287 | * |
288 | * @min_uV: Voltage given by the lowest selector (if linear mapping) | |
289 | * @uV_step: Voltage increase with each selector (if linear mapping) | |
33234e79 | 290 | * @linear_min_sel: Minimal selector for starting linear mapping |
5a523605 | 291 | * @fixed_uV: Fixed voltage of rails. |
ea38d13f | 292 | * @ramp_delay: Time to settle down after voltage change (unit: uV/us) |
5abe4f22 | 293 | * @min_dropout_uV: The minimum dropout voltage this regulator can handle |
a8dbfeed | 294 | * @linear_ranges: A constant table of possible voltage ranges. |
269cb04b CYT |
295 | * @linear_range_selectors_bitfield: A constant table of voltage range |
296 | * selectors as bitfield values. If | |
297 | * pickable ranges are used each range | |
298 | * must have corresponding selector here. | |
18e4b55f | 299 | * @n_linear_ranges: Number of entries in the @linear_ranges (and in |
269cb04b | 300 | * linear_range_selectors_bitfield if used) table(s). |
cffc9592 | 301 | * @volt_table: Voltage mapping table (if table based mapping) |
a32e0c77 | 302 | * @curr_table: Current limit mapping table (if table based mapping) |
bca7bbff | 303 | * |
18e4b55f | 304 | * @vsel_range_reg: Register for range selector when using pickable ranges |
bd3ebed9 | 305 | * and ``regulator_map_*_voltage_*_pickable`` functions. |
18e4b55f | 306 | * @vsel_range_mask: Mask for register bitfield used for range selector |
f4f4276f MV |
307 | * @range_applied_by_vsel: A flag to indicate that changes to vsel_range_reg |
308 | * are only effective after vsel_reg is written | |
bd3ebed9 | 309 | * @vsel_reg: Register for selector when using ``regulator_map_*_voltage_*`` |
4ab5b3d9 | 310 | * @vsel_mask: Mask for register bitfield used for selector |
2da8d947 BG |
311 | * @vsel_step: Specify the resolution of selector stepping when setting |
312 | * voltage. If 0, then no stepping is done (requested selector is | |
313 | * set directly), if >0 then the regulator API will ramp the | |
314 | * voltage up/down gradually each time increasing/decreasing the | |
315 | * selector by the specified step value. | |
35d838ff AL |
316 | * @csel_reg: Register for current limit selector using regmap set_current_limit |
317 | * @csel_mask: Mask for register bitfield used for current limit selector | |
c8520b4c AL |
318 | * @apply_reg: Register for initiate voltage change on the output when |
319 | * using regulator_set_voltage_sel_regmap | |
320 | * @apply_bit: Register bitfield used for initiate voltage change on the | |
321 | * output when using regulator_set_voltage_sel_regmap | |
cd6dffb4 MB |
322 | * @enable_reg: Register for control when using regmap enable/disable ops |
323 | * @enable_mask: Mask for control when using regmap enable/disable ops | |
ca5d1b35 CC |
324 | * @enable_val: Enabling value for control when using regmap enable/disable ops |
325 | * @disable_val: Disabling value for control when using regmap enable/disable ops | |
51dcdafc AL |
326 | * @enable_is_inverted: A flag to indicate set enable_mask bits to disable |
327 | * when using regulator_enable_regmap and friends APIs. | |
5838b032 NM |
328 | * @bypass_reg: Register for control when using regmap set_bypass |
329 | * @bypass_mask: Mask for control when using regmap set_bypass | |
ca5d1b35 CC |
330 | * @bypass_val_on: Enabling value for control when using regmap set_bypass |
331 | * @bypass_val_off: Disabling value for control when using regmap set_bypass | |
354794da LD |
332 | * @active_discharge_off: Enabling value for control when using regmap |
333 | * set_active_discharge | |
334 | * @active_discharge_on: Disabling value for control when using regmap | |
335 | * set_active_discharge | |
336 | * @active_discharge_mask: Mask for control when using regmap | |
337 | * set_active_discharge | |
338 | * @active_discharge_reg: Register for control when using regmap | |
339 | * set_active_discharge | |
a7a453f5 CK |
340 | * @soft_start_reg: Register for control when using regmap set_soft_start |
341 | * @soft_start_mask: Mask for control when using regmap set_soft_start | |
342 | * @soft_start_val_on: Enabling value for control when using regmap | |
343 | * set_soft_start | |
f7d37bc3 CK |
344 | * @pull_down_reg: Register for control when using regmap set_pull_down |
345 | * @pull_down_mask: Mask for control when using regmap set_pull_down | |
346 | * @pull_down_val_on: Enabling value for control when using regmap | |
347 | * set_pull_down | |
79511ed3 | 348 | * |
c049742f MV |
349 | * @ramp_reg: Register for controlling the regulator ramp-rate. |
350 | * @ramp_mask: Bitmask for the ramp-rate control register. | |
351 | * @ramp_delay_table: Table for mapping the regulator ramp-rate values. Values | |
352 | * should be given in units of V/S (uV/uS). See the | |
353 | * regulator_set_ramp_delay_regmap(). | |
0e584d46 | 354 | * @n_ramp_values: number of elements at @ramp_delay_table. |
c049742f | 355 | * |
79511ed3 | 356 | * @enable_time: Time taken for initial enable of regulator (in uS). |
871f5650 | 357 | * @off_on_delay: guard time (in uS), before re-enabling a regulator |
87e1e0f2 | 358 | * |
f7d7ad42 SS |
359 | * @poll_enabled_time: The polling interval (in uS) to use while checking that |
360 | * the regulator was actually enabled. Max upto enable_time. | |
361 | * | |
87e1e0f2 | 362 | * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode |
571a354b LG |
363 | */ |
364 | struct regulator_desc { | |
365 | const char *name; | |
69511a45 | 366 | const char *supply_name; |
a0c7b164 | 367 | const char *of_match; |
e7095c35 | 368 | bool of_match_full_name; |
a0c7b164 | 369 | const char *regulators_node; |
bfa21a0d KK |
370 | int (*of_parse_cb)(struct device_node *, |
371 | const struct regulator_desc *, | |
372 | struct regulator_config *); | |
cfcdf395 JB |
373 | int (*init_cb)(struct regulator_dev *, |
374 | struct regulator_config *); | |
571a354b | 375 | int id; |
de4a54c4 | 376 | unsigned int continuous_voltage_range:1; |
4367cfdc | 377 | unsigned n_voltages; |
a32e0c77 | 378 | unsigned int n_current_limits; |
df11e506 | 379 | const struct regulator_ops *ops; |
571a354b LG |
380 | int irq; |
381 | enum regulator_type type; | |
382 | struct module *owner; | |
4ab5b3d9 | 383 | |
bca7bbff MB |
384 | unsigned int min_uV; |
385 | unsigned int uV_step; | |
33234e79 | 386 | unsigned int linear_min_sel; |
5a523605 | 387 | int fixed_uV; |
98a175b6 | 388 | unsigned int ramp_delay; |
5abe4f22 | 389 | int min_dropout_uV; |
bca7bbff | 390 | |
60ab7f41 | 391 | const struct linear_range *linear_ranges; |
269cb04b | 392 | const unsigned int *linear_range_selectors_bitfield; |
18e4b55f | 393 | |
94d33c02 MB |
394 | int n_linear_ranges; |
395 | ||
cffc9592 | 396 | const unsigned int *volt_table; |
a32e0c77 | 397 | const unsigned int *curr_table; |
cffc9592 | 398 | |
18e4b55f MV |
399 | unsigned int vsel_range_reg; |
400 | unsigned int vsel_range_mask; | |
f4f4276f | 401 | bool range_applied_by_vsel; |
4ab5b3d9 MB |
402 | unsigned int vsel_reg; |
403 | unsigned int vsel_mask; | |
2da8d947 | 404 | unsigned int vsel_step; |
c0ea88b8 NK |
405 | unsigned int csel_reg; |
406 | unsigned int csel_mask; | |
c8520b4c AL |
407 | unsigned int apply_reg; |
408 | unsigned int apply_bit; | |
cd6dffb4 MB |
409 | unsigned int enable_reg; |
410 | unsigned int enable_mask; | |
ca5d1b35 CC |
411 | unsigned int enable_val; |
412 | unsigned int disable_val; | |
51dcdafc | 413 | bool enable_is_inverted; |
df367931 MB |
414 | unsigned int bypass_reg; |
415 | unsigned int bypass_mask; | |
ca5d1b35 CC |
416 | unsigned int bypass_val_on; |
417 | unsigned int bypass_val_off; | |
354794da LD |
418 | unsigned int active_discharge_on; |
419 | unsigned int active_discharge_off; | |
420 | unsigned int active_discharge_mask; | |
421 | unsigned int active_discharge_reg; | |
a7a453f5 CK |
422 | unsigned int soft_start_reg; |
423 | unsigned int soft_start_mask; | |
424 | unsigned int soft_start_val_on; | |
f7d37bc3 CK |
425 | unsigned int pull_down_reg; |
426 | unsigned int pull_down_mask; | |
427 | unsigned int pull_down_val_on; | |
fb8fee9e MV |
428 | unsigned int ramp_reg; |
429 | unsigned int ramp_mask; | |
430 | const unsigned int *ramp_delay_table; | |
431 | unsigned int n_ramp_values; | |
79511ed3 MB |
432 | |
433 | unsigned int enable_time; | |
871f5650 GX |
434 | |
435 | unsigned int off_on_delay; | |
87e1e0f2 | 436 | |
f7d7ad42 SS |
437 | unsigned int poll_enabled_time; |
438 | ||
87e1e0f2 | 439 | unsigned int (*of_map_mode)(unsigned int mode); |
571a354b LG |
440 | }; |
441 | ||
c172708d MB |
442 | /** |
443 | * struct regulator_config - Dynamic regulator descriptor | |
444 | * | |
445 | * Each regulator registered with the core is described with a | |
446 | * structure of this type and a struct regulator_desc. This structure | |
447 | * contains the runtime variable parts of the regulator description. | |
448 | * | |
449 | * @dev: struct device for the regulator | |
450 | * @init_data: platform provided init data, passed through by driver | |
451 | * @driver_data: private regulator data | |
452 | * @of_node: OpenFirmware node to parse for device tree bindings (may be | |
453 | * NULL). | |
cf39284d | 454 | * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is |
380a0e6f | 455 | * insufficient. |
541d052d | 456 | * @ena_gpiod: GPIO controlling regulator enable. |
c172708d MB |
457 | */ |
458 | struct regulator_config { | |
459 | struct device *dev; | |
460 | const struct regulator_init_data *init_data; | |
461 | void *driver_data; | |
462 | struct device_node *of_node; | |
65b19ce6 | 463 | struct regmap *regmap; |
65f73508 | 464 | |
e45e290a | 465 | struct gpio_desc *ena_gpiod; |
c172708d MB |
466 | }; |
467 | ||
7111c6d1 MV |
468 | /** |
469 | * struct regulator_err_state - regulator error/notification status | |
470 | * | |
471 | * @rdev: Regulator which status the struct indicates. | |
472 | * @notifs: Events which have occurred on the regulator. | |
473 | * @errors: Errors which are active on the regulator. | |
474 | * @possible_errs: Errors which can be signaled (by given IRQ). | |
475 | */ | |
476 | struct regulator_err_state { | |
477 | struct regulator_dev *rdev; | |
478 | unsigned long notifs; | |
479 | unsigned long errors; | |
480 | int possible_errs; | |
481 | }; | |
482 | ||
483 | /** | |
c049742f | 484 | * struct regulator_irq_data - regulator error/notification status data |
7111c6d1 MV |
485 | * |
486 | * @states: Status structs for each of the associated regulators. | |
487 | * @num_states: Amount of associated regulators. | |
488 | * @data: Driver data pointer given at regulator_irq_desc. | |
489 | * @opaque: Value storage for IC driver. Core does not update this. ICs | |
490 | * may want to store status register value here at map_event and | |
491 | * compare contents at 'renable' callback to see if new problems | |
492 | * have been added to status. If that is the case it may be | |
493 | * desirable to return REGULATOR_ERROR_CLEARED and not | |
494 | * REGULATOR_ERROR_ON to allow IRQ fire again and to generate | |
495 | * notifications also for the new issues. | |
496 | * | |
497 | * This structure is passed to 'map_event' and 'renable' callbacks for | |
498 | * reporting regulator status to core. | |
499 | */ | |
500 | struct regulator_irq_data { | |
501 | struct regulator_err_state *states; | |
502 | int num_states; | |
503 | void *data; | |
504 | long opaque; | |
505 | }; | |
506 | ||
507 | /** | |
508 | * struct regulator_irq_desc - notification sender for IRQ based events. | |
509 | * | |
510 | * @name: The visible name for the IRQ | |
511 | * @fatal_cnt: If this IRQ is used to signal HW damaging condition it may be | |
512 | * best to shut-down regulator(s) or reboot the SOC if error | |
513 | * handling is repeatedly failing. If fatal_cnt is given the IRQ | |
514 | * handling is aborted if it fails for fatal_cnt times and die() | |
6966df48 MV |
515 | * callback (if populated) is called. If die() is not populated |
516 | * poweroff for the system is attempted in order to prevent any | |
7111c6d1 MV |
517 | * further damage. |
518 | * @reread_ms: The time which is waited before attempting to re-read status | |
519 | * at the worker if IC reading fails. Immediate re-read is done | |
520 | * if time is not specified. | |
521 | * @irq_off_ms: The time which IRQ is kept disabled before re-evaluating the | |
522 | * status for devices which keep IRQ disabled for duration of the | |
523 | * error. If this is not given the IRQ is left enabled and renable | |
524 | * is not called. | |
525 | * @skip_off: If set to true the IRQ handler will attempt to check if any of | |
526 | * the associated regulators are enabled prior to taking other | |
527 | * actions. If no regulators are enabled and this is set to true | |
528 | * a spurious IRQ is assumed and IRQ_NONE is returned. | |
529 | * @high_prio: Boolean to indicate that high priority WQ should be used. | |
530 | * @data: Driver private data pointer which will be passed as such to | |
531 | * the renable, map_event and die callbacks in regulator_irq_data. | |
532 | * @die: Protection callback. If IC status reading or recovery actions | |
6966df48 MV |
533 | * fail fatal_cnt times this callback is called or system is |
534 | * powered off. This callback should implement a final protection | |
535 | * attempt like disabling the regulator. If protection succeeded | |
536 | * die() may return 0. If anything else is returned the core | |
537 | * assumes final protection failed and attempts to perform a | |
538 | * poweroff as a last resort. | |
7111c6d1 MV |
539 | * @map_event: Driver callback to map IRQ status into regulator devices with |
540 | * events / errors. NOTE: callback MUST initialize both the | |
541 | * errors and notifs for all rdevs which it signals having | |
542 | * active events as core does not clean the map data. | |
543 | * REGULATOR_FAILED_RETRY can be returned to indicate that the | |
544 | * status reading from IC failed. If this is repeated for | |
ad3ead1e MV |
545 | * fatal_cnt times the core will call die() callback or power-off |
546 | * the system as a last resort to protect the HW. | |
7111c6d1 MV |
547 | * @renable: Optional callback to check status (if HW supports that) before |
548 | * re-enabling IRQ. If implemented this should clear the error | |
549 | * flags so that errors fetched by regulator_get_error_flags() | |
550 | * are updated. If callback is not implemented then errors are | |
551 | * assumed to be cleared and IRQ is re-enabled. | |
552 | * REGULATOR_FAILED_RETRY can be returned to | |
553 | * indicate that the status reading from IC failed. If this is | |
554 | * repeated for 'fatal_cnt' times the core will call die() | |
ad3ead1e MV |
555 | * callback or if die() is not populated then attempt to power-off |
556 | * the system as a last resort to protect the HW. | |
7111c6d1 MV |
557 | * Returning zero indicates that the problem in HW has been solved |
558 | * and IRQ will be re-enabled. Returning REGULATOR_ERROR_ON | |
559 | * indicates the error condition is still active and keeps IRQ | |
560 | * disabled. Please note that returning REGULATOR_ERROR_ON does | |
561 | * not retrigger evaluating what events are active or resending | |
562 | * notifications. If this is needed you probably want to return | |
563 | * zero and allow IRQ to retrigger causing events to be | |
564 | * re-evaluated and re-sent. | |
565 | * | |
566 | * This structure is used for registering regulator IRQ notification helper. | |
567 | */ | |
568 | struct regulator_irq_desc { | |
569 | const char *name; | |
7111c6d1 MV |
570 | int fatal_cnt; |
571 | int reread_ms; | |
572 | int irq_off_ms; | |
573 | bool skip_off; | |
574 | bool high_prio; | |
575 | void *data; | |
576 | ||
577 | int (*die)(struct regulator_irq_data *rid); | |
578 | int (*map_event)(int irq, struct regulator_irq_data *rid, | |
579 | unsigned long *dev_mask); | |
580 | int (*renable)(struct regulator_irq_data *rid); | |
581 | }; | |
582 | ||
583 | /* | |
584 | * Return values for regulator IRQ helpers. | |
585 | */ | |
586 | enum { | |
587 | REGULATOR_ERROR_CLEARED, | |
588 | REGULATOR_FAILED_RETRY, | |
589 | REGULATOR_ERROR_ON, | |
590 | }; | |
591 | ||
a085a31a MP |
592 | /* |
593 | * struct coupling_desc | |
594 | * | |
595 | * Describes coupling of regulators. Each regulator should have | |
596 | * at least a pointer to itself in coupled_rdevs array. | |
597 | * When a new coupled regulator is resolved, n_resolved is | |
598 | * incremented. | |
599 | */ | |
600 | struct coupling_desc { | |
d8ca7d18 DO |
601 | struct regulator_dev **coupled_rdevs; |
602 | struct regulator_coupler *coupler; | |
a085a31a MP |
603 | int n_resolved; |
604 | int n_coupled; | |
605 | }; | |
606 | ||
1fa9ad52 MB |
607 | /* |
608 | * struct regulator_dev | |
609 | * | |
610 | * Voltage / Current regulator class device. One for each | |
611 | * regulator. | |
612 | * | |
613 | * This should *not* be used directly by anything except the regulator | |
614 | * core and notification injection (which should take the mutex and do | |
615 | * no other direct access). | |
616 | */ | |
617 | struct regulator_dev { | |
65f26846 | 618 | const struct regulator_desc *desc; |
5ffbd136 | 619 | int exclusive; |
1130e5b3 MB |
620 | u32 use_count; |
621 | u32 open_count; | |
f59c8f9f | 622 | u32 bypass_count; |
1fa9ad52 MB |
623 | |
624 | /* lists we belong to */ | |
625 | struct list_head list; /* list of all regulators */ | |
1fa9ad52 MB |
626 | |
627 | /* lists we own */ | |
628 | struct list_head consumer_list; /* consumers we supply */ | |
1fa9ad52 | 629 | |
a085a31a MP |
630 | struct coupling_desc coupling_desc; |
631 | ||
1fa9ad52 | 632 | struct blocking_notifier_head notifier; |
f8702f9e | 633 | struct ww_mutex mutex; /* consumer lock */ |
66cf9a7e MP |
634 | struct task_struct *mutex_owner; |
635 | int ref_cnt; | |
1fa9ad52 MB |
636 | struct module *owner; |
637 | struct device dev; | |
638 | struct regulation_constraints *constraints; | |
3801b86a | 639 | struct regulator *supply; /* for tree */ |
6261b06d | 640 | const char *supply_name; |
65b19ce6 | 641 | struct regmap *regmap; |
1fa9ad52 | 642 | |
da07ecd9 | 643 | struct delayed_work disable_work; |
da07ecd9 | 644 | |
1fa9ad52 | 645 | void *reg_data; /* regulator_dev data */ |
1130e5b3 | 646 | |
1130e5b3 | 647 | struct dentry *debugfs; |
65f73508 | 648 | |
f19b00da | 649 | struct regulator_enable_gpio *ena_pin; |
65f73508 | 650 | unsigned int ena_gpio_state:1; |
871f5650 | 651 | |
fd086045 MK |
652 | unsigned int is_switch:1; |
653 | ||
871f5650 | 654 | /* time when this regulator was disabled last time */ |
a8ce7bd8 | 655 | ktime_t last_off; |
7111c6d1 MV |
656 | int cached_err; |
657 | bool use_cached_err; | |
658 | spinlock_t err_lock; | |
42d7c87b KM |
659 | |
660 | int pw_requested_mW; | |
1fa9ad52 MB |
661 | }; |
662 | ||
6fadec4c MV |
663 | /* |
664 | * Convert error flags to corresponding notifications. | |
665 | * | |
666 | * Can be used by drivers which use the notification helpers to | |
667 | * find out correct notification flags based on the error flags. Drivers | |
668 | * can avoid storing both supported notification and error flags which | |
669 | * may save few bytes. | |
670 | */ | |
671 | static inline int regulator_err2notif(int err) | |
672 | { | |
673 | switch (err) { | |
674 | case REGULATOR_ERROR_UNDER_VOLTAGE: | |
675 | return REGULATOR_EVENT_UNDER_VOLTAGE; | |
676 | case REGULATOR_ERROR_OVER_CURRENT: | |
677 | return REGULATOR_EVENT_OVER_CURRENT; | |
678 | case REGULATOR_ERROR_REGULATION_OUT: | |
679 | return REGULATOR_EVENT_REGULATION_OUT; | |
680 | case REGULATOR_ERROR_FAIL: | |
681 | return REGULATOR_EVENT_FAIL; | |
682 | case REGULATOR_ERROR_OVER_TEMP: | |
683 | return REGULATOR_EVENT_OVER_TEMP; | |
684 | case REGULATOR_ERROR_UNDER_VOLTAGE_WARN: | |
685 | return REGULATOR_EVENT_UNDER_VOLTAGE_WARN; | |
686 | case REGULATOR_ERROR_OVER_CURRENT_WARN: | |
687 | return REGULATOR_EVENT_OVER_CURRENT_WARN; | |
688 | case REGULATOR_ERROR_OVER_VOLTAGE_WARN: | |
689 | return REGULATOR_EVENT_OVER_VOLTAGE_WARN; | |
690 | case REGULATOR_ERROR_OVER_TEMP_WARN: | |
691 | return REGULATOR_EVENT_OVER_TEMP_WARN; | |
692 | } | |
693 | return 0; | |
694 | } | |
695 | ||
696 | ||
65f26846 | 697 | struct regulator_dev * |
8f3cbcd6 CH |
698 | regulator_register(struct device *dev, |
699 | const struct regulator_desc *regulator_desc, | |
c172708d | 700 | const struct regulator_config *config); |
b33e46bc MB |
701 | struct regulator_dev * |
702 | devm_regulator_register(struct device *dev, | |
703 | const struct regulator_desc *regulator_desc, | |
704 | const struct regulator_config *config); | |
571a354b LG |
705 | void regulator_unregister(struct regulator_dev *rdev); |
706 | ||
707 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | |
708 | unsigned long event, void *data); | |
7111c6d1 MV |
709 | void *devm_regulator_irq_helper(struct device *dev, |
710 | const struct regulator_irq_desc *d, int irq, | |
711 | int irq_flags, int common_errs, | |
712 | int *per_rdev_errs, struct regulator_dev **rdev, | |
713 | int rdev_amount); | |
714 | void *regulator_irq_helper(struct device *dev, | |
715 | const struct regulator_irq_desc *d, int irq, | |
716 | int irq_flags, int common_errs, int *per_rdev_errs, | |
717 | struct regulator_dev **rdev, int rdev_amount); | |
718 | void regulator_irq_helper_cancel(void **handle); | |
a764ff77 MV |
719 | int regulator_irq_map_event_simple(int irq, struct regulator_irq_data *rid, |
720 | unsigned long *dev_mask); | |
571a354b LG |
721 | |
722 | void *rdev_get_drvdata(struct regulator_dev *rdev); | |
a5766f11 | 723 | struct device *rdev_get_dev(struct regulator_dev *rdev); |
03c87b95 | 724 | struct regmap *rdev_get_regmap(struct regulator_dev *rdev); |
571a354b LG |
725 | int rdev_get_id(struct regulator_dev *rdev); |
726 | ||
be721979 MB |
727 | int regulator_mode_to_status(unsigned int); |
728 | ||
bca7bbff MB |
729 | int regulator_list_voltage_linear(struct regulator_dev *rdev, |
730 | unsigned int selector); | |
18e4b55f MV |
731 | int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev, |
732 | unsigned int selector); | |
94d33c02 MB |
733 | int regulator_list_voltage_linear_range(struct regulator_dev *rdev, |
734 | unsigned int selector); | |
cffc9592 AL |
735 | int regulator_list_voltage_table(struct regulator_dev *rdev, |
736 | unsigned int selector); | |
bca7bbff MB |
737 | int regulator_map_voltage_linear(struct regulator_dev *rdev, |
738 | int min_uV, int max_uV); | |
18e4b55f MV |
739 | int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev, |
740 | int min_uV, int max_uV); | |
94d33c02 MB |
741 | int regulator_map_voltage_linear_range(struct regulator_dev *rdev, |
742 | int min_uV, int max_uV); | |
e843fc46 MB |
743 | int regulator_map_voltage_iterate(struct regulator_dev *rdev, |
744 | int min_uV, int max_uV); | |
fcf371ee AL |
745 | int regulator_map_voltage_ascend(struct regulator_dev *rdev, |
746 | int min_uV, int max_uV); | |
18e4b55f MV |
747 | int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev); |
748 | int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev, | |
749 | unsigned int sel); | |
4ab5b3d9 MB |
750 | int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev); |
751 | int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel); | |
cd6dffb4 MB |
752 | int regulator_is_enabled_regmap(struct regulator_dev *rdev); |
753 | int regulator_enable_regmap(struct regulator_dev *rdev); | |
754 | int regulator_disable_regmap(struct regulator_dev *rdev); | |
98a175b6 YSB |
755 | int regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
756 | unsigned int old_selector, | |
757 | unsigned int new_selector); | |
df367931 MB |
758 | int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable); |
759 | int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable); | |
a7a453f5 | 760 | int regulator_set_soft_start_regmap(struct regulator_dev *rdev); |
f7d37bc3 | 761 | int regulator_set_pull_down_regmap(struct regulator_dev *rdev); |
4ab5b3d9 | 762 | |
354794da LD |
763 | int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, |
764 | bool enable); | |
a32e0c77 AL |
765 | int regulator_set_current_limit_regmap(struct regulator_dev *rdev, |
766 | int min_uA, int max_uA); | |
767 | int regulator_get_current_limit_regmap(struct regulator_dev *rdev); | |
a5766f11 | 768 | void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); |
431cb97b SR |
769 | int regulator_find_closest_bigger(unsigned int target, const unsigned int *table, |
770 | unsigned int num_sel, unsigned int *sel); | |
fb8fee9e | 771 | int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay); |
380d2b2d | 772 | int regulator_sync_voltage_rdev(struct regulator_dev *rdev); |
a5766f11 | 773 | |
6a47b4da MV |
774 | /* |
775 | * Helper functions intended to be used by regulator drivers prior registering | |
776 | * their regulators. | |
777 | */ | |
778 | int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc, | |
779 | unsigned int selector); | |
d8ca7d18 | 780 | |
e3baacf5 MV |
781 | int regulator_desc_list_voltage_linear(const struct regulator_desc *desc, |
782 | unsigned int selector); | |
157d2230 MV |
783 | |
784 | #ifdef CONFIG_REGULATOR | |
785 | const char *rdev_get_name(struct regulator_dev *rdev); | |
786 | #else | |
787 | static inline const char *rdev_get_name(struct regulator_dev *rdev) | |
788 | { | |
789 | return NULL; | |
790 | } | |
791 | #endif | |
792 | ||
571a354b | 793 | #endif |