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