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