]>
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 | ||
40c223ef | 15 | #define MAX_COUPLED 2 |
a085a31a | 16 | |
571a354b | 17 | #include <linux/device.h> |
ced55d4e | 18 | #include <linux/notifier.h> |
571a354b | 19 | #include <linux/regulator/consumer.h> |
f8702f9e | 20 | #include <linux/ww_mutex.h> |
571a354b | 21 | |
e45e290a | 22 | struct gpio_desc; |
65b19ce6 | 23 | struct regmap; |
571a354b | 24 | struct regulator_dev; |
bfa21a0d | 25 | struct regulator_config; |
a5766f11 | 26 | struct regulator_init_data; |
f19b00da | 27 | struct regulator_enable_gpio; |
571a354b | 28 | |
853116a1 DB |
29 | enum regulator_status { |
30 | REGULATOR_STATUS_OFF, | |
31 | REGULATOR_STATUS_ON, | |
32 | REGULATOR_STATUS_ERROR, | |
33 | /* fast/normal/idle/standby are flavors of "on" */ | |
34 | REGULATOR_STATUS_FAST, | |
35 | REGULATOR_STATUS_NORMAL, | |
36 | REGULATOR_STATUS_IDLE, | |
37 | REGULATOR_STATUS_STANDBY, | |
f59c8f9f MB |
38 | /* The regulator is enabled but not regulating */ |
39 | REGULATOR_STATUS_BYPASS, | |
1beaf762 KG |
40 | /* in case that any other status doesn't apply */ |
41 | REGULATOR_STATUS_UNDEFINED, | |
853116a1 DB |
42 | }; |
43 | ||
94d33c02 | 44 | /** |
7c2330f1 RD |
45 | * struct regulator_linear_range - specify linear voltage ranges |
46 | * | |
7bd0c7ba | 47 | * Specify a range of voltages for regulator_map_linear_range() and |
94d33c02 MB |
48 | * regulator_list_linear_range(). |
49 | * | |
50 | * @min_uV: Lowest voltage in range | |
94d33c02 MB |
51 | * @min_sel: Lowest selector for range |
52 | * @max_sel: Highest selector for range | |
53 | * @uV_step: Step size | |
54 | */ | |
55 | struct regulator_linear_range { | |
56 | unsigned int min_uV; | |
94d33c02 MB |
57 | unsigned int min_sel; |
58 | unsigned int max_sel; | |
59 | unsigned int uV_step; | |
60 | }; | |
61 | ||
8828bae4 AL |
62 | /* Initialize struct regulator_linear_range */ |
63 | #define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \ | |
64 | { \ | |
65 | .min_uV = _min_uV, \ | |
66 | .min_sel = _min_sel, \ | |
67 | .max_sel = _max_sel, \ | |
68 | .uV_step = _step_uV, \ | |
69 | } | |
70 | ||
571a354b LG |
71 | /** |
72 | * struct regulator_ops - regulator operations. | |
73 | * | |
3b2a6061 DB |
74 | * @enable: Configure the regulator as enabled. |
75 | * @disable: Configure the regulator as disabled. | |
d87b969d WS |
76 | * @is_enabled: Return 1 if the regulator is enabled, 0 if not. |
77 | * May also return negative errno. | |
c8e7e464 MB |
78 | * |
79 | * @set_voltage: Set the voltage for the regulator within the range specified. | |
80 | * The driver should select the voltage closest to min_uV. | |
e8eef82b MB |
81 | * @set_voltage_sel: Set the voltage for the regulator using the specified |
82 | * selector. | |
e843fc46 | 83 | * @map_voltage: Convert a voltage into a selector |
84b3a7c9 DA |
84 | * @get_voltage: Return the currently configured voltage for the regulator; |
85 | * return -ENOTRECOVERABLE if regulator can't be read at | |
86 | * bootup and hasn't been set yet. | |
476c2d83 | 87 | * @get_voltage_sel: Return the currently configured voltage selector for the |
84b3a7c9 DA |
88 | * regulator; return -ENOTRECOVERABLE if regulator can't |
89 | * be read at bootup and hasn't been set yet. | |
4367cfdc DB |
90 | * @list_voltage: Return one of the supported voltages, in microvolts; zero |
91 | * if the selector indicates a voltage that is unusable on this system; | |
92 | * or negative errno. Selectors range from zero to one less than | |
93 | * regulator_desc.n_voltages. Voltages may be reported in any order. | |
c8e7e464 | 94 | * |
c8e7e464 | 95 | * @set_current_limit: Configure a limit for a current-limited regulator. |
89009e18 | 96 | * The driver should select the current closest to max_uA. |
3b2a6061 | 97 | * @get_current_limit: Get the configured limit for a current-limited regulator. |
36e4f839 | 98 | * @set_input_current_limit: Configure an input limit. |
c8e7e464 | 99 | * |
abf2f825 LB |
100 | * @set_over_current_protection: Support capability of automatically shutting |
101 | * down when detecting an over current event. | |
102 | * | |
670666b9 LD |
103 | * @set_active_discharge: Set active discharge enable/disable of regulators. |
104 | * | |
9f653251 | 105 | * @set_mode: Set the configured operating mode for the regulator. |
3b2a6061 | 106 | * @get_mode: Get the configured operating mode for the regulator. |
1b5b4221 | 107 | * @get_error_flags: Get the current error(s) for the regulator. |
3b2a6061 DB |
108 | * @get_status: Return actual (not as-configured) status of regulator, as a |
109 | * REGULATOR_STATUS value (or negative errno) | |
c8e7e464 MB |
110 | * @get_optimum_mode: Get the most efficient operating mode for the regulator |
111 | * when running with the specified parameters. | |
8f4490e0 | 112 | * @set_load: Set the load for the regulator. |
c8e7e464 | 113 | * |
f59c8f9f MB |
114 | * @set_bypass: Set the regulator in bypass mode. |
115 | * @get_bypass: Get the regulator bypass mode state. | |
116 | * | |
31aae2be | 117 | * @enable_time: Time taken for the regulator voltage output voltage to |
77af1b26 | 118 | * stabilise after being enabled, in microseconds. |
6f0b2c69 YSB |
119 | * @set_ramp_delay: Set the ramp delay for the regulator. The driver should |
120 | * select ramp delay equal to or less than(closest) ramp_delay. | |
73e705bf MK |
121 | * @set_voltage_time: Time taken for the regulator voltage output voltage |
122 | * to stabilise after being set to a new value, in microseconds. | |
123 | * The function receives the from and to voltage as input, it | |
124 | * should return the worst case. | |
77af1b26 LW |
125 | * @set_voltage_time_sel: Time taken for the regulator voltage output voltage |
126 | * to stabilise after being set to a new value, in microseconds. | |
73e705bf MK |
127 | * The function receives the from and to voltage selector as |
128 | * input, it should return the worst case. | |
c751ad0d | 129 | * @set_soft_start: Enable soft start for the regulator. |
31aae2be | 130 | * |
c8e7e464 MB |
131 | * @set_suspend_voltage: Set the voltage for the regulator when the system |
132 | * is suspended. | |
133 | * @set_suspend_enable: Mark the regulator as enabled when the system is | |
134 | * suspended. | |
135 | * @set_suspend_disable: Mark the regulator as disabled when the system is | |
136 | * suspended. | |
137 | * @set_suspend_mode: Set the operating mode for the regulator when the | |
138 | * system is suspended. | |
3b2a6061 | 139 | * |
23c779b9 SB |
140 | * @set_pull_down: Configure the regulator to pull down when the regulator |
141 | * is disabled. | |
142 | * | |
3b2a6061 DB |
143 | * This struct describes regulator operations which can be implemented by |
144 | * regulator chip drivers. | |
571a354b LG |
145 | */ |
146 | struct regulator_ops { | |
147 | ||
4367cfdc DB |
148 | /* enumerate supported voltages */ |
149 | int (*list_voltage) (struct regulator_dev *, unsigned selector); | |
150 | ||
571a354b | 151 | /* get/set regulator voltage */ |
3a93f2a9 MB |
152 | int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV, |
153 | unsigned *selector); | |
e843fc46 | 154 | int (*map_voltage)(struct regulator_dev *, int min_uV, int max_uV); |
e8eef82b | 155 | int (*set_voltage_sel) (struct regulator_dev *, unsigned selector); |
571a354b | 156 | int (*get_voltage) (struct regulator_dev *); |
476c2d83 | 157 | int (*get_voltage_sel) (struct regulator_dev *); |
571a354b LG |
158 | |
159 | /* get/set regulator current */ | |
160 | int (*set_current_limit) (struct regulator_dev *, | |
161 | int min_uA, int max_uA); | |
162 | int (*get_current_limit) (struct regulator_dev *); | |
163 | ||
36e4f839 | 164 | int (*set_input_current_limit) (struct regulator_dev *, int lim_uA); |
3a003bae | 165 | int (*set_over_current_protection) (struct regulator_dev *); |
670666b9 | 166 | int (*set_active_discharge) (struct regulator_dev *, bool enable); |
36e4f839 | 167 | |
571a354b LG |
168 | /* enable/disable regulator */ |
169 | int (*enable) (struct regulator_dev *); | |
170 | int (*disable) (struct regulator_dev *); | |
171 | int (*is_enabled) (struct regulator_dev *); | |
172 | ||
fde297bb | 173 | /* get/set regulator operating mode (defined in consumer.h) */ |
571a354b LG |
174 | int (*set_mode) (struct regulator_dev *, unsigned int mode); |
175 | unsigned int (*get_mode) (struct regulator_dev *); | |
176 | ||
1b5b4221 AH |
177 | /* retrieve current error flags on the regulator */ |
178 | int (*get_error_flags)(struct regulator_dev *, unsigned int *flags); | |
179 | ||
77af1b26 | 180 | /* Time taken to enable or set voltage on the regulator */ |
31aae2be | 181 | int (*enable_time) (struct regulator_dev *); |
6f0b2c69 | 182 | int (*set_ramp_delay) (struct regulator_dev *, int ramp_delay); |
73e705bf MK |
183 | int (*set_voltage_time) (struct regulator_dev *, int old_uV, |
184 | int new_uV); | |
77af1b26 LW |
185 | int (*set_voltage_time_sel) (struct regulator_dev *, |
186 | unsigned int old_selector, | |
187 | unsigned int new_selector); | |
31aae2be | 188 | |
57f66b78 SB |
189 | int (*set_soft_start) (struct regulator_dev *); |
190 | ||
853116a1 DB |
191 | /* report regulator status ... most other accessors report |
192 | * control inputs, this reports results of combining inputs | |
193 | * from Linux (and other sources) with the actual load. | |
3b2a6061 | 194 | * returns REGULATOR_STATUS_* or negative errno. |
853116a1 DB |
195 | */ |
196 | int (*get_status)(struct regulator_dev *); | |
197 | ||
571a354b LG |
198 | /* get most efficient regulator operating mode for load */ |
199 | unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, | |
200 | int output_uV, int load_uA); | |
8f4490e0 BA |
201 | /* set the load on the regulator */ |
202 | int (*set_load)(struct regulator_dev *, int load_uA); | |
571a354b | 203 | |
f59c8f9f MB |
204 | /* control and report on bypass mode */ |
205 | int (*set_bypass)(struct regulator_dev *dev, bool enable); | |
206 | int (*get_bypass)(struct regulator_dev *dev, bool *enable); | |
207 | ||
571a354b | 208 | /* the operations below are for configuration of regulator state when |
3de89609 | 209 | * its parent PMIC enters a global STANDBY/HIBERNATE state */ |
571a354b LG |
210 | |
211 | /* set regulator suspend voltage */ | |
212 | int (*set_suspend_voltage) (struct regulator_dev *, int uV); | |
213 | ||
214 | /* enable/disable regulator in suspend state */ | |
215 | int (*set_suspend_enable) (struct regulator_dev *); | |
216 | int (*set_suspend_disable) (struct regulator_dev *); | |
217 | ||
fde297bb | 218 | /* set regulator suspend operating mode (defined in consumer.h) */ |
571a354b | 219 | int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); |
23c779b9 | 220 | |
0380cf7d | 221 | int (*resume)(struct regulator_dev *rdev); |
f7efad10 | 222 | |
23c779b9 | 223 | int (*set_pull_down) (struct regulator_dev *); |
571a354b LG |
224 | }; |
225 | ||
226 | /* | |
227 | * Regulators can either control voltage or current. | |
228 | */ | |
229 | enum regulator_type { | |
230 | REGULATOR_VOLTAGE, | |
231 | REGULATOR_CURRENT, | |
232 | }; | |
233 | ||
234 | /** | |
c172708d | 235 | * struct regulator_desc - Static regulator descriptor |
571a354b | 236 | * |
c172708d MB |
237 | * Each regulator registered with the core is described with a |
238 | * structure of this type and a struct regulator_config. This | |
239 | * structure contains the non-varying parts of the regulator | |
240 | * description. | |
c8e7e464 MB |
241 | * |
242 | * @name: Identifying name for the regulator. | |
69511a45 | 243 | * @supply_name: Identifying the regulator supply |
a0c7b164 MB |
244 | * @of_match: Name used to identify regulator in DT. |
245 | * @regulators_node: Name of node containing regulator definitions in DT. | |
bfa21a0d KK |
246 | * @of_parse_cb: Optional callback called only if of_match is present. |
247 | * Will be called for each regulator parsed from DT, during | |
248 | * init_data parsing. | |
249 | * The regulator_config passed as argument to the callback will | |
250 | * be a copy of config passed to regulator_register, valid only | |
251 | * for this particular call. Callback may freely change the | |
252 | * config but it cannot store it for later usage. | |
253 | * Callback should return 0 on success or negative ERRNO | |
254 | * indicating failure. | |
c8e7e464 MB |
255 | * @id: Numerical identifier for the regulator. |
256 | * @ops: Regulator operations table. | |
0ba4887c | 257 | * @irq: Interrupt number for the regulator. |
c8e7e464 MB |
258 | * @type: Indicates if the regulator is a voltage or current regulator. |
259 | * @owner: Module providing the regulator, used for refcounting. | |
bca7bbff | 260 | * |
bd7a2b60 PM |
261 | * @continuous_voltage_range: Indicates if the regulator can set any |
262 | * voltage within constrains range. | |
bca7bbff | 263 | * @n_voltages: Number of selectors available for ops.list_voltage(). |
a32e0c77 | 264 | * @n_current_limits: Number of selectors available for current limits |
bca7bbff MB |
265 | * |
266 | * @min_uV: Voltage given by the lowest selector (if linear mapping) | |
267 | * @uV_step: Voltage increase with each selector (if linear mapping) | |
33234e79 | 268 | * @linear_min_sel: Minimal selector for starting linear mapping |
5a523605 | 269 | * @fixed_uV: Fixed voltage of rails. |
ea38d13f | 270 | * @ramp_delay: Time to settle down after voltage change (unit: uV/us) |
5abe4f22 | 271 | * @min_dropout_uV: The minimum dropout voltage this regulator can handle |
a8dbfeed | 272 | * @linear_ranges: A constant table of possible voltage ranges. |
18e4b55f MV |
273 | * @linear_range_selectors: A constant table of voltage range selectors. |
274 | * If pickable ranges are used each range must | |
275 | * have corresponding selector here. | |
276 | * @n_linear_ranges: Number of entries in the @linear_ranges (and in | |
277 | * linear_range_selectors if used) table(s). | |
cffc9592 | 278 | * @volt_table: Voltage mapping table (if table based mapping) |
a32e0c77 | 279 | * @curr_table: Current limit mapping table (if table based mapping) |
bca7bbff | 280 | * |
18e4b55f MV |
281 | * @vsel_range_reg: Register for range selector when using pickable ranges |
282 | * and regulator_regmap_X_voltage_X_pickable functions. | |
283 | * @vsel_range_mask: Mask for register bitfield used for range selector | |
4ab5b3d9 MB |
284 | * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ |
285 | * @vsel_mask: Mask for register bitfield used for selector | |
35d838ff AL |
286 | * @csel_reg: Register for current limit selector using regmap set_current_limit |
287 | * @csel_mask: Mask for register bitfield used for current limit selector | |
c8520b4c AL |
288 | * @apply_reg: Register for initiate voltage change on the output when |
289 | * using regulator_set_voltage_sel_regmap | |
290 | * @apply_bit: Register bitfield used for initiate voltage change on the | |
291 | * output when using regulator_set_voltage_sel_regmap | |
cd6dffb4 MB |
292 | * @enable_reg: Register for control when using regmap enable/disable ops |
293 | * @enable_mask: Mask for control when using regmap enable/disable ops | |
ca5d1b35 CC |
294 | * @enable_val: Enabling value for control when using regmap enable/disable ops |
295 | * @disable_val: Disabling value for control when using regmap enable/disable ops | |
51dcdafc AL |
296 | * @enable_is_inverted: A flag to indicate set enable_mask bits to disable |
297 | * when using regulator_enable_regmap and friends APIs. | |
5838b032 NM |
298 | * @bypass_reg: Register for control when using regmap set_bypass |
299 | * @bypass_mask: Mask for control when using regmap set_bypass | |
ca5d1b35 CC |
300 | * @bypass_val_on: Enabling value for control when using regmap set_bypass |
301 | * @bypass_val_off: Disabling value for control when using regmap set_bypass | |
354794da LD |
302 | * @active_discharge_off: Enabling value for control when using regmap |
303 | * set_active_discharge | |
304 | * @active_discharge_on: Disabling value for control when using regmap | |
305 | * set_active_discharge | |
306 | * @active_discharge_mask: Mask for control when using regmap | |
307 | * set_active_discharge | |
308 | * @active_discharge_reg: Register for control when using regmap | |
309 | * set_active_discharge | |
a7a453f5 CK |
310 | * @soft_start_reg: Register for control when using regmap set_soft_start |
311 | * @soft_start_mask: Mask for control when using regmap set_soft_start | |
312 | * @soft_start_val_on: Enabling value for control when using regmap | |
313 | * set_soft_start | |
f7d37bc3 CK |
314 | * @pull_down_reg: Register for control when using regmap set_pull_down |
315 | * @pull_down_mask: Mask for control when using regmap set_pull_down | |
316 | * @pull_down_val_on: Enabling value for control when using regmap | |
317 | * set_pull_down | |
79511ed3 MB |
318 | * |
319 | * @enable_time: Time taken for initial enable of regulator (in uS). | |
871f5650 | 320 | * @off_on_delay: guard time (in uS), before re-enabling a regulator |
87e1e0f2 JMC |
321 | * |
322 | * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode | |
571a354b LG |
323 | */ |
324 | struct regulator_desc { | |
325 | const char *name; | |
69511a45 | 326 | const char *supply_name; |
a0c7b164 MB |
327 | const char *of_match; |
328 | const char *regulators_node; | |
bfa21a0d KK |
329 | int (*of_parse_cb)(struct device_node *, |
330 | const struct regulator_desc *, | |
331 | struct regulator_config *); | |
571a354b | 332 | int id; |
de4a54c4 | 333 | unsigned int continuous_voltage_range:1; |
4367cfdc | 334 | unsigned n_voltages; |
a32e0c77 | 335 | unsigned int n_current_limits; |
df11e506 | 336 | const struct regulator_ops *ops; |
571a354b LG |
337 | int irq; |
338 | enum regulator_type type; | |
339 | struct module *owner; | |
4ab5b3d9 | 340 | |
bca7bbff MB |
341 | unsigned int min_uV; |
342 | unsigned int uV_step; | |
33234e79 | 343 | unsigned int linear_min_sel; |
5a523605 | 344 | int fixed_uV; |
98a175b6 | 345 | unsigned int ramp_delay; |
5abe4f22 | 346 | int min_dropout_uV; |
bca7bbff | 347 | |
94d33c02 | 348 | const struct regulator_linear_range *linear_ranges; |
18e4b55f MV |
349 | const unsigned int *linear_range_selectors; |
350 | ||
94d33c02 MB |
351 | int n_linear_ranges; |
352 | ||
cffc9592 | 353 | const unsigned int *volt_table; |
a32e0c77 | 354 | const unsigned int *curr_table; |
cffc9592 | 355 | |
18e4b55f MV |
356 | unsigned int vsel_range_reg; |
357 | unsigned int vsel_range_mask; | |
4ab5b3d9 MB |
358 | unsigned int vsel_reg; |
359 | unsigned int vsel_mask; | |
c0ea88b8 NK |
360 | unsigned int csel_reg; |
361 | unsigned int csel_mask; | |
c8520b4c AL |
362 | unsigned int apply_reg; |
363 | unsigned int apply_bit; | |
cd6dffb4 MB |
364 | unsigned int enable_reg; |
365 | unsigned int enable_mask; | |
ca5d1b35 CC |
366 | unsigned int enable_val; |
367 | unsigned int disable_val; | |
51dcdafc | 368 | bool enable_is_inverted; |
df367931 MB |
369 | unsigned int bypass_reg; |
370 | unsigned int bypass_mask; | |
ca5d1b35 CC |
371 | unsigned int bypass_val_on; |
372 | unsigned int bypass_val_off; | |
354794da LD |
373 | unsigned int active_discharge_on; |
374 | unsigned int active_discharge_off; | |
375 | unsigned int active_discharge_mask; | |
376 | unsigned int active_discharge_reg; | |
a7a453f5 CK |
377 | unsigned int soft_start_reg; |
378 | unsigned int soft_start_mask; | |
379 | unsigned int soft_start_val_on; | |
f7d37bc3 CK |
380 | unsigned int pull_down_reg; |
381 | unsigned int pull_down_mask; | |
382 | unsigned int pull_down_val_on; | |
79511ed3 MB |
383 | |
384 | unsigned int enable_time; | |
871f5650 GX |
385 | |
386 | unsigned int off_on_delay; | |
87e1e0f2 JMC |
387 | |
388 | unsigned int (*of_map_mode)(unsigned int mode); | |
571a354b LG |
389 | }; |
390 | ||
c172708d MB |
391 | /** |
392 | * struct regulator_config - Dynamic regulator descriptor | |
393 | * | |
394 | * Each regulator registered with the core is described with a | |
395 | * structure of this type and a struct regulator_desc. This structure | |
396 | * contains the runtime variable parts of the regulator description. | |
397 | * | |
398 | * @dev: struct device for the regulator | |
399 | * @init_data: platform provided init data, passed through by driver | |
400 | * @driver_data: private regulator data | |
401 | * @of_node: OpenFirmware node to parse for device tree bindings (may be | |
402 | * NULL). | |
cf39284d | 403 | * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is |
380a0e6f | 404 | * insufficient. |
541d052d | 405 | * @ena_gpiod: GPIO controlling regulator enable. |
c172708d MB |
406 | */ |
407 | struct regulator_config { | |
408 | struct device *dev; | |
409 | const struct regulator_init_data *init_data; | |
410 | void *driver_data; | |
411 | struct device_node *of_node; | |
65b19ce6 | 412 | struct regmap *regmap; |
65f73508 | 413 | |
e45e290a | 414 | struct gpio_desc *ena_gpiod; |
c172708d MB |
415 | }; |
416 | ||
a085a31a MP |
417 | /* |
418 | * struct coupling_desc | |
419 | * | |
420 | * Describes coupling of regulators. Each regulator should have | |
421 | * at least a pointer to itself in coupled_rdevs array. | |
422 | * When a new coupled regulator is resolved, n_resolved is | |
423 | * incremented. | |
424 | */ | |
425 | struct coupling_desc { | |
426 | struct regulator_dev *coupled_rdevs[MAX_COUPLED]; | |
427 | int n_resolved; | |
428 | int n_coupled; | |
429 | }; | |
430 | ||
1fa9ad52 MB |
431 | /* |
432 | * struct regulator_dev | |
433 | * | |
434 | * Voltage / Current regulator class device. One for each | |
435 | * regulator. | |
436 | * | |
437 | * This should *not* be used directly by anything except the regulator | |
438 | * core and notification injection (which should take the mutex and do | |
439 | * no other direct access). | |
440 | */ | |
441 | struct regulator_dev { | |
65f26846 | 442 | const struct regulator_desc *desc; |
5ffbd136 | 443 | int exclusive; |
1130e5b3 MB |
444 | u32 use_count; |
445 | u32 open_count; | |
f59c8f9f | 446 | u32 bypass_count; |
1fa9ad52 MB |
447 | |
448 | /* lists we belong to */ | |
449 | struct list_head list; /* list of all regulators */ | |
1fa9ad52 MB |
450 | |
451 | /* lists we own */ | |
452 | struct list_head consumer_list; /* consumers we supply */ | |
1fa9ad52 | 453 | |
a085a31a MP |
454 | struct coupling_desc coupling_desc; |
455 | ||
1fa9ad52 | 456 | struct blocking_notifier_head notifier; |
f8702f9e | 457 | struct ww_mutex mutex; /* consumer lock */ |
66cf9a7e MP |
458 | struct task_struct *mutex_owner; |
459 | int ref_cnt; | |
1fa9ad52 MB |
460 | struct module *owner; |
461 | struct device dev; | |
462 | struct regulation_constraints *constraints; | |
3801b86a | 463 | struct regulator *supply; /* for tree */ |
6261b06d | 464 | const char *supply_name; |
65b19ce6 | 465 | struct regmap *regmap; |
1fa9ad52 | 466 | |
da07ecd9 | 467 | struct delayed_work disable_work; |
da07ecd9 | 468 | |
1fa9ad52 | 469 | void *reg_data; /* regulator_dev data */ |
1130e5b3 | 470 | |
1130e5b3 | 471 | struct dentry *debugfs; |
65f73508 | 472 | |
f19b00da | 473 | struct regulator_enable_gpio *ena_pin; |
65f73508 | 474 | unsigned int ena_gpio_state:1; |
871f5650 | 475 | |
fd086045 MK |
476 | unsigned int is_switch:1; |
477 | ||
871f5650 GX |
478 | /* time when this regulator was disabled last time */ |
479 | unsigned long last_off_jiffy; | |
1fa9ad52 MB |
480 | }; |
481 | ||
65f26846 MB |
482 | struct regulator_dev * |
483 | regulator_register(const struct regulator_desc *regulator_desc, | |
c172708d | 484 | const struct regulator_config *config); |
b33e46bc MB |
485 | struct regulator_dev * |
486 | devm_regulator_register(struct device *dev, | |
487 | const struct regulator_desc *regulator_desc, | |
488 | const struct regulator_config *config); | |
571a354b | 489 | void regulator_unregister(struct regulator_dev *rdev); |
b33e46bc | 490 | void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev); |
571a354b LG |
491 | |
492 | int regulator_notifier_call_chain(struct regulator_dev *rdev, | |
493 | unsigned long event, void *data); | |
494 | ||
495 | void *rdev_get_drvdata(struct regulator_dev *rdev); | |
a5766f11 | 496 | struct device *rdev_get_dev(struct regulator_dev *rdev); |
03c87b95 | 497 | struct regmap *rdev_get_regmap(struct regulator_dev *rdev); |
571a354b LG |
498 | int rdev_get_id(struct regulator_dev *rdev); |
499 | ||
be721979 MB |
500 | int regulator_mode_to_status(unsigned int); |
501 | ||
bca7bbff MB |
502 | int regulator_list_voltage_linear(struct regulator_dev *rdev, |
503 | unsigned int selector); | |
18e4b55f MV |
504 | int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev, |
505 | unsigned int selector); | |
94d33c02 MB |
506 | int regulator_list_voltage_linear_range(struct regulator_dev *rdev, |
507 | unsigned int selector); | |
cffc9592 AL |
508 | int regulator_list_voltage_table(struct regulator_dev *rdev, |
509 | unsigned int selector); | |
bca7bbff MB |
510 | int regulator_map_voltage_linear(struct regulator_dev *rdev, |
511 | int min_uV, int max_uV); | |
18e4b55f MV |
512 | int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev, |
513 | int min_uV, int max_uV); | |
94d33c02 MB |
514 | int regulator_map_voltage_linear_range(struct regulator_dev *rdev, |
515 | int min_uV, int max_uV); | |
e843fc46 MB |
516 | int regulator_map_voltage_iterate(struct regulator_dev *rdev, |
517 | int min_uV, int max_uV); | |
fcf371ee AL |
518 | int regulator_map_voltage_ascend(struct regulator_dev *rdev, |
519 | int min_uV, int max_uV); | |
18e4b55f MV |
520 | int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev); |
521 | int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev, | |
522 | unsigned int sel); | |
4ab5b3d9 MB |
523 | int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev); |
524 | int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel); | |
cd6dffb4 MB |
525 | int regulator_is_enabled_regmap(struct regulator_dev *rdev); |
526 | int regulator_enable_regmap(struct regulator_dev *rdev); | |
527 | int regulator_disable_regmap(struct regulator_dev *rdev); | |
98a175b6 YSB |
528 | int regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
529 | unsigned int old_selector, | |
530 | unsigned int new_selector); | |
df367931 MB |
531 | int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable); |
532 | int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable); | |
a7a453f5 | 533 | int regulator_set_soft_start_regmap(struct regulator_dev *rdev); |
f7d37bc3 | 534 | int regulator_set_pull_down_regmap(struct regulator_dev *rdev); |
4ab5b3d9 | 535 | |
354794da LD |
536 | int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, |
537 | bool enable); | |
a32e0c77 AL |
538 | int regulator_set_current_limit_regmap(struct regulator_dev *rdev, |
539 | int min_uA, int max_uA); | |
540 | int regulator_get_current_limit_regmap(struct regulator_dev *rdev); | |
a5766f11 LG |
541 | void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); |
542 | ||
f8702f9e DO |
543 | void regulator_lock(struct regulator_dev *rdev); |
544 | void regulator_unlock(struct regulator_dev *rdev); | |
545 | ||
6a47b4da MV |
546 | /* |
547 | * Helper functions intended to be used by regulator drivers prior registering | |
548 | * their regulators. | |
549 | */ | |
550 | int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc, | |
551 | unsigned int selector); | |
571a354b | 552 | #endif |